useState vs useRef: When to Use Each in React

How I Understood useRef When I first saw useRef, I thought: “Okay… is this another useState?” 😅 But then I noticed something strange. I changed a value. The UI didn’t re-render. Nothing refreshed. And that’s when it clicked 💡 👉 useRef is like a sticky note. It remembers a value… but doesn’t shout to React about it. useState says: “Hey React! I changed. Update the UI!” useRef says: “Just remember this quietly.” That’s why I use useRef for: Accessing DOM elements (input focus, scroll) Storing previous values Timers, intervals, and mutable data The big lesson for me 👇 Not every change needs a re-render. Now when I choose between useState and useRef, I ask one question: 👉 Should the UI update or not? Still learning. Still simplifying. 🚀 #ReactJS #useCallback #FrontendDeveloper #LearningInPublic #Frontend #LearningInPublic #JavaScript #WebDevelopment #DeveloperJourney

  • text

To view or add a comment, sign in

Explore content categories