Note that this is not the recommended way to build your app. We recommend
using conflict-free data types and the useStorage and useMutation hooks,
to take full advantage of our features.
You can easily add Liveblocks to an existing useState hook by broadcasting and
listening to events.
import{ useState }from"react";import{ useBroadcastEvent, useEventListener }from"./liveblocks.config"; functionuseCustomState(){const[state, setState]=useState();const broadcast =useBroadcastEvent(); // Update useState and broadcast an eventconstsetStateAndBroadcast=(newValue)=>{setState(newValue);broadcast({ type:"STATE_UPDATE", data: newValue });}; // Listen for the broadcast eventuseEventListener(({ event })=>{if(event.type ==="STATE_UPDATE"){setState(event.data);}}); return[state, setStateAndBroadcast];}