ReactJS and Redux offer a new paradigm as far as developing the front end of applications goes. Both have relatively simple APIs and after spending a little time are pretty easy to grasp from a technical point of view. But from a design perspective, I have been unable to find recommendations on best practices or pitfalls.
Where can I find recommendations or advice on how to design my global Redux store? Keeping the entire state of an application in a global store seems like it could get unwieldy rapidly. What should I be sure to avoid in doing so? What about the actions that modify the global state? Is it better to make fewer actions that can do different things based on the action data, or many more specific actions?
In most cases, you should be using the configureStore method of the @reduxjs/toolkit package instead of calling createStore directly.
The best way to access your store in a component is to use the connect() function, that creates a new component that wraps around your existing one.
Redux can have only a single store in your application. Whenever a store is created in Redux, you need to specify the reducer. A reducer is a function that returns the next state of app.
This is a great question, but it's a bit difficult to tangibly answer because so much of it is an "it depends" question. But, I would highly recommend taking an in-depth look at the redux.js.org docs. There's lots of little bits of wisdom in there about suggestions for shaping an API or reducing duplication or general unwieldiness.
Additionally, I'd add a few general tips:
Hope that helps a bit!
See also:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With