Loading...
useEffect(() => {
const conn = connect(roomId);
conn.on('connected', () => showToast('Connected', theme));
return () => conn.disconnect();
}, [roomId, theme]);const onConnected = useEffectEvent(() => showToast('Connected', theme));
useEffect(() => {
const conn = connect(roomId);
conn.on('connected', () => onConnected());
return () => conn.disconnect();
}, [roomId]);Changing theme no longer reconnects to the room, and the toast still uses the current theme.
useRef workarounds for reading the latest props, and lint warnings are not silenced.useCallback returns a function that changes when its dependencies change. An Effect Event always sees the latest values and is meant to be called only from Effects.
Yes. It is imported from 'react', and the React Hooks lint rules know not to require it in dependency arrays.