Redux FAQ
Table of Contents
- General
- Reducers
- Organizing State
- Store Setup
- Can or should I create multiple stores? Can I import my store directly, and use it in components myself?
- Is it OK to have more than one middleware chain in my store enhancer? What is the difference between next and dispatch in a middleware function?
- How do I subscribe to only a portion of the state? Can I get the dispatched action as part of the subscription?
- Actions
- Why should type be a string, or at least serializable? Why should my action types be constants?
- Is there always a one-to-one mapping between reducers and actions?
- 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?
- What async middleware should I use? How do you decide between thunks, sagas, observables, or something else?
- Should I dispatch multiple actions in a row from one action creator?
- Immutable Data
- Code Structure
- What should my file structure look like? How should I group my action creators and reducers in my project? Where should my selectors go?
- How should I split my logic between reducers and action creators? Where should my “business logic” go?
- Why should I use action creators?
- Where should websockets and other persistent connections live?
- How can I use the Redux store in non-component files?
- Performance
- How well does Redux “scale” in terms of performance and architecture?
- Won't calling “all my reducers” for each action be slow?
- Do I have to deep-clone my state in a reducer? Isn't copying my state going to be slow?
- How can I reduce the number of store update events?
- Will having “one state tree” cause memory problems? Will dispatching many actions take up memory?
- Will caching remote data cause memory problems?
- Design Decisions
- Why doesn't Redux pass the state and action to subscribers?
- Why doesn't Redux support using classes for actions and reducers?
- Why does the middleware signature use currying?
- Why does applyMiddleware use a closure for dispatch?
- Why doesn't
combineReducers
include a third argument with the entire state when it calls each reducer? - Why doesn't mapDispatchToProps allow use of return values from
getState()
ormapStateToProps()
?
- React Redux
- Why should I use React-Redux?
- Why isn't my component re-rendering, or my mapStateToProps running?
- Why is my component re-rendering too often?
- How can I speed up my mapStateToProps?
- Why don't I have this.props.dispatch available in my connected component?
- Should I only connect my top component, or can I connect multiple components in my tree?
- Miscellaneous