Skip to content

Commit 5a0610e

Browse files
committed
Finish prettifying FAQ
1 parent dd0c8a3 commit 5a0610e

File tree

1 file changed

+35
-44
lines changed

1 file changed

+35
-44
lines changed

docs/FAQ.md

Lines changed: 35 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ In general, use Redux when you have reasonable amounts of data changing over tim
2727
- [Stack Overflow: Why should I use Redux in this example?](http://stackoverflow.com/questions/35675339/why-should-i-use-redux-in-this-example)
2828
- [Stack Overflow: What could be the downsides of using Redux instead of Flux?](http://stackoverflow.com/questions/32021763/what-could-be-the-downsides-of-using-redux-instead-of-flux)
2929

30-
### Can Redux only be used with React?
30+
### Can Redux only be used with React?
3131

3232
Redux can be used as a data store for any UI layer. The most common usage is with React and React Native, but there are bindings available for Angular, Angular 2, Vue, Mithril, and more. Redux simply provides a subscription mechanism which can be used by any other code. That said it is most useful when combined with a declarative view implementation that can infer the UI updates from the state changes.
3333

@@ -467,103 +467,94 @@ For non-connected components, you may want to check what props are being passed
467467
#### Further information
468468

469469
**Discussions**
470-
- [Stack Overflow - Can a React Redux app scale as well as Backbone?](http://stackoverflow.com/questions/34782249/can-a-react-redux-app-really-scale-as-well-as-say-backbone-even-with-reselect)
470+
- [Stack Overflow: Can a React Redux app scale as well as Backbone?](http://stackoverflow.com/questions/34782249/can-a-react-redux-app-really-scale-as-well-as-say-backbone-even-with-reselect)
471471
- [React.js pure render performance anti-pattern](https://medium.com/@esamatti/react-js-pure-render-performance-anti-pattern-fb88c101332f)
472472
- [A Deep Dive into React Perf Debugging](http://benchling.engineering/deep-dive-react-perf-debugging/)
473473

474474

475-
### How can I speed up my mapStateToProps?
475+
### How can I speed up my `mapStateToProps`?
476476

477-
While React Redux does work to minimize the number of times that your `mapStateToProps` function is called, it's still a good idea to ensure that your `mapStateToProps` runs quickly and also minimizes the amount of work it does. The common recommended approach is to create memoized "selector" functions using the [Reselect](https://github.com/reactjs/reselect) library. These selectors can be combined and composed together, and selectors later in a pipeline will only run if their inputs have changed. This means you can create selectors that do things like filtering or sorting, and ensure that the real work only happens if needed.
477+
While React Redux does work to minimize the number of times that your `mapStateToProps` function is called, its still a good idea to ensure that your `mapStateToProps` runs quickly and also minimizes the amount of work it does. The common recommended approach is to create memoized selector functions using [Reselect](https://github.com/reactjs/reselect). These selectors can be combined and composed together, and selectors later in a pipeline will only run if their inputs have changed. This means you can create selectors that do things like filtering or sorting, and ensure that the real work only happens if needed.
478478

479479
#### Further information
480+
480481
**Documentation**
481482
- [Recipes: Computed Derived Data](recipes/ComputingDerivedData.md)
482483

483484
**Discussions**
485+
- [#815: Working with Data Structures](https://github.com/reactjs/redux/issues/815)
486+
- [Reselect #47: Memoizing Hierarchical Selectors](https://github.com/reactjs/reselect/issues/47)
484487

485-
- [#815 - Working with Data Structures](https://github.com/reactjs/redux/issues/815)
486-
- [Reselect #47 - Memoizing Hierarchical Selectors](https://github.com/reactjs/reselect/issues/47)
487-
488-
489-
### Why don't I have `this.props.dispatch` available in my connected component?
490-
491-
The `connect` function takes two primary arguments, both optional. The first, `mapStateToProps`, is a function you provide to pull data from the store when it changes, and pass those values as props to your component. The second, `mapDispatchToProps`, is a function you provide to make use of the store's `dispatch` function, usually by creating pre-bound versions of action creators that will automatically dispatch their actions as soon as they are called.
488+
### Why don’t I have `this.props.dispatch` available in my connected component?
492489

493-
If you do not provide your own `mapDispatchToProps` function when calling `connect`, React Redux will provide a default version, which simply returns the `dispatch` function as a prop. That means that if you _do_ provide your own function, `dispatch` is _not_ automatically provided. If you still want it available as a prop, you need to explicitly return it yourself in your `mapDispatchToProps` implementation.
490+
The `connect()` function takes two primary arguments, both optional. The first, `mapStateToProps`, is a function you provide to pull data from the store when it changes, and pass those values as props to your component. The second, `mapDispatchToProps`, is a function you provide to make use of the store’s `dispatch` function, usually by creating pre-bound versions of action creators that will automatically dispatch their actions as soon as they are called.
494491

492+
If you do not provide your own `mapDispatchToProps` function when calling `connect()`, React Redux will provide a default version, which simply returns the `dispatch` function as a prop. That means that if you *do* provide your own function, `dispatch` is *not* automatically provided. If you still want it available as a prop, you need to explicitly return it yourself in your `mapDispatchToProps` implementation.
495493

496494
#### Further information
497-
**Documentation**
498-
- [React Redux API: connect](https://github.com/reactjs/react-redux/blob/master/docs/api.md#connectmapstatetoprops-mapdispatchtoprops-mergeprops-options)
499495

496+
**Documentation**
497+
- [React Redux API: connect()](https://github.com/reactjs/react-redux/blob/master/docs/api.md#connectmapstatetoprops-mapdispatchtoprops-mergeprops-options)
500498

501499
**Discussions**
502-
503-
- [React Redux #89 - can i wrap multi actionCreators into one props with name?](https://github.com/reactjs/react-redux/issues/89)
504-
- [React Redux #145 - consider always passing down dispatch regardless of what mapDispatchToProps does](https://github.com/reactjs/react-redux/issues/145)
505-
- [React Redux #255 - this.props.dispatch is undefined if using mapDispatchToProps](https://github.com/reactjs/react-redux/issues/255)
506-
- [Stack Overflow - http://stackoverflow.com/questions/34458261/how-to-get-simple-dispatch-from-this-props-using-connect-w-redux/34458710](How to get simple dispatch from this.props using connect w/ Redux?)
507-
500+
- [React Redux #89: can i wrap multi actionCreators into one props with name?](https://github.com/reactjs/react-redux/issues/89)
501+
- [React Redux #145: consider always passing down dispatch regardless of what mapDispatchToProps does](https://github.com/reactjs/react-redux/issues/145)
502+
- [React Redux #255: this.props.dispatch is undefined if using mapDispatchToProps](https://github.com/reactjs/react-redux/issues/255)
503+
- [Stack Overflow: http://stackoverflow.com/questions/34458261/how-to-get-simple-dispatch-from-this-props-using-connect-w-redux/34458710](How to get simple dispatch from this.props using connect w/ Redux?)
508504

509505
### Should I only connect my top component, or can I connect multiple components in my tree?
510506

511-
Early Redux documentation advised that you should only have a few connected components, near the top of your component tree. However, time and experience has shown that that generally requires a few components to know too much about the data requirements of all their descendants, and forces them to pass down a confusing number of props.
507+
Early Redux documentation advised that you should only have a few connected components near the top of your component tree. However, time and experience has shown that that generally requires a few components to know too much about the data requirements of all their descendants, and forces them to pass down a confusing number of props.
512508

513-
The current suggested best practice is to categorize your components as "presentational" or "container", and extract a connected container component wherever it makes sense:
509+
The current suggested best practice is to categorize your components as presentational or container” components, and extract a connected container component wherever it makes sense:
514510

515-
> Emphasizing "one container component at the top" in Redux examples was a mistake. Don't take this as a maxim. Try to keep your presentation components separate. Create container components by connecting them when it's convenient. Whenever you feel like you're duplicating code in parent components to provide data for same kinds of children, time to extract a container. Generally as soon as you feel a parent knows too much about "personal" data / actions of its children, time to extract a container.
511+
> Emphasizing one container component at the top in Redux examples was a mistake. Dont take this as a maxim. Try to keep your presentation components separate. Create container components by connecting them when its convenient. Whenever you feel like youre duplicating code in parent components to provide data for same kinds of children, time to extract a container. Generally as soon as you feel a parent knows too much about personal data or actions of its children, time to extract a container.
516512
517513
In general, try to find a balance between understandable data flow and areas of responsibility with your components.
518514

519515
#### Further information
516+
520517
**Documentation**
521518
- [Basics: Usage with React](basics/UsageWithReact.md)
522519

523-
524520
**Discussions**
525521
- [Presentational and Container Components](https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0)
526-
- [Twitter - emphasizing "one container" was a mistake](https://twitter.com/dan_abramov/status/668585589609005056)
527-
- [#419 - Recommended usage of connect](https://github.com/reactjs/redux/issues/419)
528-
- [#756 - container vs component?](https://github.com/reactjs/redux/issues/756)
529-
- [#1176 - Redux+React with only stateless components](https://github.com/reactjs/redux/issues/1176)
530-
- [Stack Overflow - can a dumb component use a Redux container?](http://stackoverflow.com/questions/34992247/can-a-dumb-component-use-render-redux-container-component)
531-
532-
522+
- [Twitter: emphasizing "one container" was a mistake](https://twitter.com/dan_abramov/status/668585589609005056)
523+
- [#419: Recommended usage of connect](https://github.com/reactjs/redux/issues/419)
524+
- [#756: container vs component?](https://github.com/reactjs/redux/issues/756)
525+
- [#1176: Redux+React with only stateless components](https://github.com/reactjs/redux/issues/1176)
526+
- [Stack Overflow: can a dumb component use a Redux container?](http://stackoverflow.com/questions/34992247/can-a-dumb-component-use-render-redux-container-component)
533527

534528
## Miscellaneous
535529

536-
### Are there any larger, "real" Redux projects?
530+
### Are there any larger, real Redux projects?
537531

538-
The Redux "examples" folder has several sample projects of varying complexity, including a "real-world" example. While many companies are using Redux, most of their applications are proprietary and not available. A large number of Redux-related projects can be found on Github, such as [Sound-Redux](https://github.com/andrewngu/sound-redux).
532+
The Redux examples folder has several sample projects of varying complexity, including a real-world example. While many companies are using Redux, most of their applications are proprietary and not available. A large number of Redux-related projects can be found on Github, such as [SoundRedux](https://github.com/andrewngu/sound-redux).
539533

540534
#### Further information
535+
541536
**Documentation**
542537
- [Introduction: Examples](introduction/Examples.md)
543538

544-
545539
**Discussions**
546-
547-
- [Reddit - Large open source react/redux projects?](https://www.reddit.com/r/reactjs/comments/496db2/large_open_source_reactredux_projects/)
548-
- [HN - Is there any huge web application built using Redux?](https://news.ycombinator.com/item?id=10710240)
549-
540+
- [Reddit: Large open source react/redux projects?](https://www.reddit.com/r/reactjs/comments/496db2/large_open_source_reactredux_projects/)
541+
- [HN: Is there any huge web application built using Redux?](https://news.ycombinator.com/item?id=10710240)
550542

551543
### How can I implement authentication in Redux?
552544

553-
Authentication is essential to any real application. When going about authentication you must keep in mind that nothing changes with how you should organize your application and you should implement authentication in the same way you would any other feature. It is straightforward:
545+
Authentication is essential to any real application. When going about authentication you must keep in mind that nothing changes with how you should organize your application and you should implement authentication in the same way you would any other feature. It is relatively straightforward:
554546

555-
1. Create action constants for LoginSuccess, LoginFailure, etc.
547+
1. Create action constants for `LOGIN_SUCCESS`, `LOGIN_FAILURE`, etc.
556548

557-
2. Create actionCreators that take in a type, credentials, a flag that signifies if authentication is true or false, a token, or errorMessage as a payload.
549+
2. Create action creators that take in credentials, a flag that signifies whether authentication succeeded, a token, or an error message as the payload.
558550

559-
3. Create an async action creator with redux-thunk middleware or any middleware you see fit to fire a network request to an api that returns a token if the credentials are valid and proceeds to save in local storage or a response to the user if it is a failure which is handled by the appropriate actionCreators that you made in step 2.
551+
3. Create an async action creator with Redux Thunk middleware or any middleware you see fit to fire a network request to an API that returns a token if the credentials are valid. Then save the token in the local storage or show a response to the user if it failed. You can perform these side effects from the action creators you wrote in the previous step.
560552

561-
4. Create a reducer that can return the next state for each possible authentication case (LoginSuccess, LogoutFailure).
553+
4. Create a reducer that returns the next state for each possible authentication case (`LOGIN_SUCCESS`, `LOGIN_FAILURE`, etc).
562554

563555
#### Further information
564556

565557
**Discussions**
566-
567558
- [Authentication with JWT by Auth0](https://auth0.com/blog/2016/01/04/secure-your-react-and-redux-app-with-jwt-authentication/)
568559
- [Tips to Handle Authentication in Redux](https://medium.com/@MattiaManzati/tips-to-handle-authentication-in-redux-2-introducing-redux-saga-130d6872fbe7)
569560
- [react-redux-jwt-auth-example](https://github.com/joshgeller/react-redux-jwt-auth-example)

0 commit comments

Comments
 (0)