Misly16 / use-lanyard

React hook for Lanyard for tracking your Discord presence.

Home Page:https://www.npmjs.com/package/use-lanyard

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

use-lanyard

React hook for lanyard, an easy way to track your Discord presence through REST or WebSocket.

It's easy to use and fully typed. With REST, the useLanyard hook returns an SWR SWRResponse. Over WebSocket, it will return the Data type.

import {useLanyard} from 'use-lanyard';

const DISCORD_ID = '268798547439255572';

export function Activity() {
	const {data: activity} = useLanyard(DISCORD_ID);

	return <>...</>;
}

Socket

There is also a hook for using the WebSocket that Lanyard provides, here's an example:

import {useLanyardWs} from 'use-lanyard';

const DISCORD_ID = '268798547439255572';

export function Activity() {
	const activity = useLanyardWs(DISCORD_ID);

	return <>...</>;
}

Advanced usage with TypeScript

If you need access to the underlying response types, you can import them as follows.

import { Data, Activity, ...etc } from 'use-lanyard';
// See src/types.ts for all types

Acknowledgements

About

React hook for Lanyard for tracking your Discord presence.

https://www.npmjs.com/package/use-lanyard

License:MIT License


Languages

Language:TypeScript 89.1%Language:HTML 10.9%