Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How big is too big for a redux store?

So, I am considering putting our entire translation object into the redux store before hydrating onto the client. This translation object is approx 50kb gzipped, and 115kb uncompressed.

Our entire site is translated, so this translation object basically represents all non-dynamic copy across the website. If it's hydrated onto the client on the initial http request, it should provide for an instantaneous browsing experience, at least for in-house copy.

However, I'm wondering if this is way, way too big for a redux store?

like image 379
j_d Avatar asked Dec 01 '16 14:12

j_d


People also ask

How big can a Redux store be?

A Redux store doesn't have a limit on the amount of data stored, so you can pretty much use it to store almost anything, including bulky JSON data, data in table form, etc.

Is Redux overkill?

Redux is overkill Speaking of the Context API, it works well when you have to share global state data — no need to pass data as props all the time for each component. Indeed, sometimes this is enough, and a sophisticated external state management solution like Redux is overkill.

How many stores should a Redux application have?

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.


2 Answers

You should load the translations separately. Webpack allows for code splitting which can help. Or you can just use a script tag.

The reason for loading it separately is so the browser can cache it. This allows it to be loaded only once per user. Since the HTML page generated by React is dynamic and the store you pass down is also dynamic, they cannot be cached.

With such a large lump of data, loading it on each page load is just a bad idea.

Also, the store is for state. It's to handle stuff that changes. Putting static data in there is not what it is meant to handle. This doesn't mean it can't be done, but it's just not a good match.

like image 67
DDS Avatar answered Sep 17 '22 15:09

DDS


I don't think there's a 'too big' size for a Redux store. However it should contain only application state. The translation objects should be in the code and you should access them through a i18n library. The state should as much have a field which says what language you must show to the user.

like image 28
Facundo Matteo Avatar answered Sep 16 '22 15:09

Facundo Matteo