score:0

  const useStore = create(set => ({ scratches: 0, ... }))
    function Component() {
      // Fetch initial state
      const scratchRef = useRef(useStore.getState().scratches)
      // Connect to the store on mount, disconnect on unmount, catch state-changes in a reference
      useEffect(() => useStore.subscribe(
        scratches => (scratchRef.current = scratches),
        state => state.scratches
      ), [])

Related Query

More Query from same tag