Redux state - maximum recommended size

喜欢而已 提交于 2019-12-13 15:53:41

问题


I'm building a project management app and I'm still struggling with a question - what to store in Redux state and what load "on demand".

Is there any known "maximum recommended size" of a Redux state? Dozens of kilobytes, hundreds of kilobytes, units of megabytes, ...?


回答1:


Keep in mind that, at the end of the day, Redux is just a paradigm for "how" to save your information in memory. It doesn't add or reduce the amount of data you are keeping track of.

As an example: let's say your app was keeping track of to-do tasks. Before Redux, you had a React class of this pseudo-structure:

class TaskList {
  state = { tasks: [] }
  componentWillMount => goGetTheTasks().then(tasks => this.setState({ tasks }))
  render = <div>{this.state.tasks.map()}</div>
}

With Redux, your store looks like this:

{
    tasks: []
}

In both cases, you are saving the same data (the same tasks array) in memory.

Perhaps you could further share certain concerns that you have about your state growing too large. Also keep in mind that anything you can put in your store, you can take out of your store. And—you're not forced to put every byte inside your one store either. Still want to use component state for certain things? That's up to you—but you'll lose out on the advantages of having that data accessible from a central source.



来源:https://stackoverflow.com/questions/45669409/redux-state-maximum-recommended-size

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!