Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

(Stale) useDedupedRender

Do not use this. Only here for archiving purposes.

A React hook for deduping renders. Was supposed to be used so:

function MyComponent() {
  const render = useDedupedRender(fn)
  function fn() {
    // ...
    setWhateverState(...)
  }

  useEffect(() => {
    function handleClick() {
      render(fn)
    }
    function handleKeyDown() {
      render(fn)
    }
    // ... register event handlers
  }, [])
}

This is so that we can gather all the events from the current frame, and acting on them.

Implementation-wise, the render returned from useDedupedRender calls requestAnimationFrame, which ultimately calls the fn passed to useDedupedRender.

Unfortunately, setState inside requestAnimationFrame inside a React event handler is queued next frame, not the current one. Which sucks. So don't use this.

See alternative solution at https://x.com/_chenglou/status/1862262785801167228

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages