TLDR Dev · ARTICLES & TUTORIALS

3 WAYS TO STORE VARIABLES IN REACT, AND WHY YOU SHOULDN'T SLEEP ON USEREF

readwriterachel.com4 min read

Summary from the TLDR Dev newsletter

There are three ways to store variables in React, with a particular focus on the `useRef` hook. Vanilla JavaScript variables are temporary and do not cause UI updates, while `useState` variables persist, update the UI, and are essential for reactive components.`useRef` allows data to persist and be mutable across renders without triggering a re-render of the UI.