Am I wrong for skipping state management libraries in my React app?
Asked by
One.More.Circuit
I'm developing a React application without using any global state management libraries like Redux. Right now, I'm simply relying on local state for things like whether the sidebar is open or which tab is selected. I use Tanstack Query for fetching data and managing the logged-in user's state based on the query/cache results. Whenever I make changes, I just refetch the necessary queries. This strategy has worked for me, but I often hear others praising the use of libraries like Redux, and I can't help but feel like I'm missing something important. Should I reconsider my approach to state management in this context?
Answers
Honestly, you're using state management already with Tanstack Query, so you're doing just fine. It's pretty common to manage local states for UI interactions while handling data fetching through a library like Tanstack. Redux really shines when you have complex scenarios like collaborative apps or when components need to read and write shared states frequently. If you don't face those issues, you don't need to complicate things!
Reply to this answer
You're not crazy at all! Using Tanstack Query along with local component state is a perfectly valid approach for many applications. It's known as 'server state first,' and it works well because most global states, like user settings or info, are actually server states. Tanstack Query does a great job handling those aspects for you. Only look into global state management libraries like Redux if you start facing the need for complex shared state across disconnected components. Otherwise, keep it simple!
Reply to this answer
Add your answer
Answers are reviewed before publication.
pH.test: I totally agree with that! Keeping data layers separate is often cleaner and avoids a lot of unnecessary bloat.