When It's Not Good to Use React State

Full Stack Developer | Freelancer | JavaScript | React | Nodejs.
Loves sharing knowledge through technical articles.
Dev.to: https://dev.to/myogeshchavan97
https://linktr.ee/myogeshchavan97
Search for a command to run...

Full Stack Developer | Freelancer | JavaScript | React | Nodejs.
Loves sharing knowledge through technical articles.
Dev.to: https://dev.to/myogeshchavan97
https://linktr.ee/myogeshchavan97
Hey, Yogesh Chavan every time I learn something new from your post, keep posting it really help.
Thanks for sharing.
Glad to hear that anil kapse. Thank you 🙏
I found this tip really helpful and anticipating your Redux course.
thanks for sharing Yogesh Chavan.
Thank you so much Ayodele Samuel Adebayo
In this tutorial, you will build a Task Management App using Next.js 16 and Prisma 7 from scratch. By creating this app, you will learn: How to set up Prisma 7 with the new Rust-free architecture How to configure a database with Prisma's driver ada...

If you're a React/Next.js developer who diligently updated your packages last week after the critical React2Shell vulnerability (CVE-2025-55182), I have some frustrating news: you need to update again. Security researchers, while probing the patches ...

Is your React app dragging its feet, but you can’t pinpoint the cause? You might think you’re following the best practices, but some common development patterns are actually degrading your app’s performance behind the scenes. In this article, we’ll u...

How to Use Separate SSH Keys for Company and Personal GitHub Accounts Managing multiple GitHub accounts is a common challenge for developers who juggle both personal and professional projects. It becomes even more complex when you want to use differe...

Have you ever built a React app only to realize that users from different countries can't use it effectively because it only supports English? In this tutorial, you'll learn how to build truly global React application using internationalization (i18n...

In React, whenever we are working with any data, we always use the state for storing that data which may be a string, number or any complex object.
This is fine if you are using that state while rendering the component or If you want to do something when the state value changes but If you are using that state just for storing data and not using it for rendering or not passed as a prop to other components then you should not use state.
Because whenever the state value changes, React will re-render the component and also all its child components will get re-rendered.
Take a look at the below code:
Here, we are storing the count in the state but we are not using it in render and also not passing it to other components as a prop.
You might be using it just to check how many clicks happened or for some other purpose. But this will make your app re-render for every button click just because you used state.
Here's a Code Sandbox Demo.
Here's a Preview link for the above Code Sandbox Demo.
If you open the preview link about and open your react dev tools, then in the components tab click the wheel icon and select the checkbox which says Highlight updates when components render, then you will be able to see when and which components get re-rendered.

Check out the below Gif to see it in action.

If we have some components which render a large amount of data for example users list then just a single click will re-render the component for every user which is not good. So React provides another way of handling that.
If you want to store some data but don’t want to re-render the app, then you can use the
useRefhook provided by React.
Take a look at the same code written using useRef.
The inputRef in the above code contains a current property that holds the actual value of the ref.

As you can see, the count is incrementing but the app is not re-rendering.
Here's a Code Sandbox Demo.
Here's a Preview link for the above Code Sandbox Demo.
If you are using a class component instead of a functional component then you can use React.createRef method to create a ref.
Here's a Code Sandbox Demo.
Here's a Preview link for the above Code Sandbox Demo.
You should only use state when you're using it in the render method or passing it as a prop.
If you want to store data just for keeping track of some value, you should use ref instead of the state.
This will avoid extra re-rendering because re-rendering many times might cause performance issue which may not be visible for smaller applications but it will affect large application where large data processing is happening.
Starting with ES6, there are many useful additions to JavaScript like
You can learn everything about all the ES6+ features in detail in my Mastering Modern JavaScript book.
Check out free preview contents of the book here.
Also, you can check out my free Introduction to React Router course to learn React Router from scratch.
Want to stay up to date with regular content regarding JavaScript, React, Node.js? Follow me on LinkedIn.