import { useContext , useEffect , useState } from 'react' ; import ChimeSdkWrapper from '../chime/ChimeSdkWrapper' ; import getChimeContext from '../context/getChimeContext' ; import RosterType from '../types/RosterType' ; export default function useRoster ( ) { const chime = useContext ( getChimeContext ( ) ) ; const [ roster , setRoster ] = useState < RosterType > ( chime ?. roster || { } ) ; useEffect ( ( ) => { const callback = ( newRoster ) => { setRoster ( { ... newRoster } as RosterType ) ; } ; chime ?. subscribeToRosterUpdate ( callback ) ; return ( ) => { chime ?. unsubscribeFromRosterUpdate ( callback ) ; } ; } , [ ] ) ; return roster ; }