The Startup
Published in

The Startup

How to Deal With Circular Dependencies in React Hooks

Photo by Matt Seymour on Unsplash

July 27, 2020

TL;DR

Use this hook:

// This hook provides a ref which is perpetually up to date but will
// not trigger any renders. This is useful for resolving circular
// references in dependency arrays.
export default function useNoRenderRef(currentValue) {
const ref = useRef(currentValue);

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store