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 <>...</>;
}
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 <>...</>;
}
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
- Phineas Walton – Author of lanyard
- Alistair Smith – Author of this library