Ad

When I Should Use A Store In ReactJs

- 1 answer

I have some questions about the store in ReactJS/Flux implementation.

Basically, I have all my API request which use store. But sometimes, I think store is an overkill features.

A simple example : I just want display a list of the five last user who have registered on the home of my dashboard. I never want to refresh this list until the user refresh the browser. Should I use a store just for that ?! Or maybe I can create a "global" store for my home page where I include all this little things like this (static display of data requested by the API).

I have another question about store, how much a medium-size application have store ? Because mine have already a lot of store (20-30).

You create one store by page ?! By models ?! By components ?!

Thanks for you response.

Ad

Answer

TL;DR: many Reducers, one Store.

You tagged this with Redux so I'm going to answer based on the assumption that you're either using Redux or want to use as your Flux implementation.

Regarding the number of Stores, from the Redux docs:

It’s important to note that you’ll only have a single store in a Redux application. When you want to split your data handling logic, you’ll use reducer composition instead of many stores.

So it might be that you want to create a home Reducer to handle all the API responses for your homepage and save those to your single Store.

Ad
source: stackoverflow.com
Ad