import React from "react" ; import { usePresence } from "~hooks" ; import type { Presence , User } from "~types" ; const PRESENCE = "presence" ; example export function useSelf < T extends Presence > ( initialPresence ) { const presence = usePresence ( ) ; const [ self , setSelf ] = React . useState < User < T > > ( { id : presence . clientID , presence : initialPresence } ) ; React . useEffect ( ( ) => { presence . setLocalState ( self ) ; } , [ presence , self ] ) ; const updatePresence = React . useCallback ( ( overrides ) => { const updatedPresence = { ... self . presence , ... overrides } ; presence . setLocalState ( { id : presence . clientID , presence : updatedPresence } ) ; setSelf ( presence . getLocalState ( ) as User < T > ) ; } , [ presence , self ] ) ; return { self , updatePresence } ; }