-
-
Notifications
You must be signed in to change notification settings - Fork 555
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore(deps): update to lodash to 4.17.15 * chore(deps): update proptypes to 15.7.2 * docs(integrations): add docs for how to reference data from state for reselect selectors - #614
- Loading branch information
1 parent
c1b1b89
commit 78171b9
Showing
5 changed files
with
58 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Reselect | ||
|
||
There are a number of reasons to use state selectors, as mentioned in the [relesect docs](https://github.com/reduxjs/reselect): | ||
|
||
> * Selectors can compute derived data, allowing Redux to store the minimal possible state. | ||
> * Selectors are efficient. A selector is not recomputed unless one of its arguments changes. | ||
> * Selectors are composable. They can be used as input to other selectors. | ||
For more information, about why this is important, checkout the [motivation for memoized selectors sections of the reselect docs](https://github.com/reduxjs/reselect#motivation-for-memoized-selectors) | ||
|
||
## State Selectors | ||
|
||
Select only what you need from state in your selectors instead of the whole firebase/firestore state object: | ||
|
||
```js | ||
import { createSelector } from 'reselect'; | ||
import { connect } from 'react-redux' | ||
import { get, sumBy } from 'lodash' | ||
|
||
const netTotalSelector = createSelector( | ||
state => get(state, 'firestore.data.products'), | ||
products => sumBy(products, 'price') | ||
) | ||
|
||
connect((state) => ({ | ||
netTotal: netTotalSelector(state) | ||
}))(Component) | ||
``` | ||
|
||
In this case Reselect will memoize the products object. That means that even if there's any update to other parts of redux state (including firebase/firestore), the memoized products object will stay the same until there is an update to the products themselves. | ||
|
||
See [issue #614](https://github.com/prescottprue/react-redux-firebase/issues/614) for more info. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters