The rest is up to you, but you might find that keeping everything serializable helps debug and reproduce issues.Įncapsulating and centralizing commonly used pieces of code is a key concept in programming. We can't reliably enforce serializable actions for performance reasons, so Redux only checks that every action is a plain object, and that the type is a string. Actions only need to be serializable by the time they actually reach the store and are passed to the reducers. Note that it is okay to use Symbols, Promises, or other non-serializable values in an action if the action is intended for use by middleware. Strings are serializable and easily self-descriptive, and so are a better choice. Using something like a Symbol for the type value or using instanceof checks for actions themselves would break that. Should I dispatch multiple actions in a row from one action creator?Īctions Why should type be a string? Why should my action types be constants? Īs with state, serializable actions enable several of Redux's defining features, such as time travel debugging, and recording and replaying actions.What async middleware should I use? How do you decide between thunks, sagas, observables, or something else?. How can I represent “side effects” such as AJAX calls? Why do we need things like “action creators”, “thunks”, and “middleware” to do async behavior?.Is there always a one-to-one mapping between reducers and actions?.Why should type be a string, or at least serializable? Why should my action types be constants?.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |