When starting a new React project, it’s always a good idea to put together some guidelines that you and your team will follow to make the code scalable.
In this post, I will share with you a handful of insights from my years of using React that will help you to determine your own project guideline.
React is a library that manages the UI based on its current state. As a developer, it’s your job to organize where to keep the state that makes up your application. Some developers prefer to keep every single piece of data inside the redux store to keep track of all available states.
But do you really need to dispatch an action to your state manager just to open or close a simple dropdown menu? And do other parts of your application need to know about the value of that contact form? Form values tend to be short-lived and only used by the component that renders the form.
Rather than using Redux to keep track of every single state inside your application, it’s better to keep some state local to avoid over-engineering your application.
As a rule of thumb, you can ask these questions:
Components using local states are more independent and predictable.
#react #javascript #frontend #react native