This is particularly useful if you have to attach to a document event (in my case, a keyboard event). Unless you re-attach the event whenever anything changes, you will have stale props. Now, we don't want that, do we?
In my case, I had a hook which accepted this argument:
interface Props {
isDisabled: () => boolean
onToggleChat: () => void
onToggleMute: () => void
onFullscreen: () => void
onFullscreenExit: () => void
onPlay: () => void
onForward: () => void
onBackward: () => void
}
function usePlayerHotkeys(props: Props) {
const props = usePropRef(hookProps)
useEffect(() => {
function handleKeyDown() {
//
}
document.addEventListener('keydown', handleKeyDown)
return () => {
document.removeEventListener('keydown', handleKeyDown)
}
}, [])
}