@rexlabs/pusher
React hooks for pusher.
Getting started
yarn add --dev @rexlabs/pusher
function App(props) {
return (
<PusherProvider
appID={config.PUSHER_KEY}
cluser={config.PUSHER_CLUSTER}
forceTLS={config.stage !== 'local'}
>
<ComponentThatUsesPusher />
</PusherProvider>
);
}
function ComponentThatUsesPusher(props) {
// subscribe to channel
const channel = useChannel(`channel_id_or_name`);
// subscribe to event within the channel
useEvent(
channel,
'event_name',
() => {
/* do something when the event happens */
},
[] // array of callback deps
);
return <Box>...</Box>;
}