单个redux存储中的所有应用程序数据

时间:2017-12-12 14:38:52

标签: javascript reactjs redux react-redux

我是redux的新手。 我有一个五页的应用程序,每个页面都有一些表格。

我应该将所有页面数据保存在商店中,即使是那些当前没有呈现的页面吗?

如果答案是肯定的,那么当我总共有大量数据时会发生什么?(5000条记录)

如果答案是否定的,请帮助我理解它以及如何管理不同的页面状态。

1 个答案:

答案 0 :(得分:0)

There is no clear cut way to this problem as is with most programming conundrum.

storing all the state information in redux is alright and manageable especially if you don't really have a lot of states or moving parts in the store. but in larger applications, you don't really want to update the redux store every time someone clicks an input field, especially if that is a trivial state it is updating(like states of a text field like focused, pristine and dirty). getting a good ratio of stuff in the redux store and the local state store can get tricky at first but you'll get the hang of it with more experience, though a general rule of thumb is

does this state affect another component?

If you answered yes, then you might want to move that to redux. otherwise leaving it in the local state store is fine. As for your concern with dealing with large data, take note that you should not load ALL the data on page load. load only the things you need(better if you can preload these) and fetch additional data as needed.

i.e. if you have an index page that should display the top 10 most popular tv shows this season. instead of seeding your index page with all the shows in your database, just load the 10 most popular tv shows. then proceed to fetch data you need as you navigate around the app