You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Do I have to put all my state into Redux? Should I ever use React's `setState()`?](#do-i-have-to-put-all-my-state-into-redux-should-i-ever-use-reacts-setstate)
14
+
-[Do I have to put all my state into Redux? Should I ever use React's `useState` or `useReducer`?](#do-i-have-to-put-all-my-state-into-redux-should-i-ever-use-reacts-usestate-or-usereducer)
15
15
-[Further information](#further-information)
16
16
-[Can I put functions, promises, or other non-serializable items in my store state?](#can-i-put-functions-promises-or-other-non-serializable-items-in-my-store-state)
17
17
-[Further information](#further-information-1)
@@ -22,7 +22,7 @@ sidebar_label: Organizing State
22
22
23
23
## Organizing State
24
24
25
-
### Do I have to put all my state into Redux? Should I ever use React's `setState()`?
25
+
### Do I have to put all my state into Redux? Should I ever use React's `useState` or `useReducer`?
26
26
27
27
There is no “right” answer for this. Some users prefer to keep every single piece of data in Redux, to maintain a fully serializable and controlled version of their application at all times. Others prefer to keep non-critical or UI state, such as “is this dropdown currently open”, inside a component's internal state.
28
28
@@ -37,37 +37,18 @@ Some common rules of thumb for determining what kind of data should be put into
37
37
- Do you want to cache the data (ie, use what's in state if it's already there instead of re-requesting it)?
38
38
- Do you want to keep this data consistent while hot-reloading UI components (which may lose their internal state when swapped)?
39
39
40
-
There are a number of community packages that implement various approaches for storing per-component state in a Redux store instead, such as [redux-component](https://github.com/tomchentw/redux-component), [redux-react-local](https://github.com/threepointone/redux-react-local), and more. It's also possible to apply Redux's principles and concept of reducers to the task of updating local component state as well, along the lines of `this.setState( (previousState) => reducer(previousState, someAction))`.
41
40
42
41
#### Further information
43
42
44
43
**Articles**
45
44
46
45
-[When (and when not) to reach for Redux](https://changelog.com/posts/when-and-when-not-to-reach-for-redux)
47
-
-[Finding `state`'s place with React and Redux](https://medium.com/@adamrackis/finding-state-s-place-with-react-and-redux-e9a586630172)
48
-
-[A Case for setState](https://medium.com/@zackargyle/a-case-for-setstate-1f1c47cd3f73)
49
-
-[How to handle state in React: the missing FAQ](https://medium.com/react-ecosystem/how-to-handle-state-in-react-6f2d3cd73a0c)
50
-
-[Where to Hold React Component Data: state, store, static, and this](https://medium.freecodecamp.com/where-do-i-belong-a-guide-to-saving-react-component-data-in-state-store-static-and-this-c49b335e2a00)
51
-
-[The 5 Types of React Application State](http://jamesknelson.com/5-types-react-application-state/)
52
-
-[Shape Your Redux Store Like Your Database](https://hackernoon.com/shape-your-redux-store-like-your-database-98faa4754fd5)
53
46
54
47
**Discussions**
55
48
56
-
-[#159: Investigate using Redux for pseudo-local component state](https://github.com/reduxjs/redux/issues/159)
57
-
-[#1098: Using Redux in reusable React component](https://github.com/reduxjs/redux/issues/1098)
58
-
-[#1287: How to choose between Redux's store and React's state?](https://github.com/reduxjs/redux/issues/1287)
59
-
-[#1385: What are the disadvantages of storing all your state in a single immutable atom?](https://github.com/reduxjs/redux/issues/1385)
60
-
-[Twitter: Should I keep something in React component state?](https://twitter.com/dan_abramov/status/749710501916139520)
61
-
-[Twitter: Using a reducer to update a component](https://twitter.com/dan_abramov/status/736310245945933824)
62
-
-[React Forums: Redux and global state vs local state](https://discuss.reactjs.org/t/redux-and-global-state-vs-local-state/4187)
63
49
-[Reddit: "When should I put something into my Redux store?"](https://www.reddit.com/r/reactjs/comments/4w04to/when_using_redux_should_all_asynchronous_actions/d63u4o8)
64
-
-[Stack Overflow: Why is state all in one place, even state that isn't global?](https://stackoverflow.com/questions/35664594/redux-why-is-state-all-in-one-place-even-state-that-isnt-global)
65
50
-[Stack Overflow: Should all component state be kept in Redux store?](https://stackoverflow.com/questions/35328056/react-redux-should-all-component-states-be-kept-in-redux-store)
### Can I put functions, promises, or other non-serializable items in my store state?
72
53
73
54
It is highly recommended that you only put plain serializable objects, arrays, and primitives into your store. It's _technically_ possible to insert non-serializable items into the store, but doing so can break the ability to persist and rehydrate the contents of a store, as well as interfere with time-travel debugging.
0 commit comments