-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve docs for "factory function" syntax #797
Comments
I would like this too. I've never been clear on what another level of indirection affords you when constructing these functions. I prefer the simplest object syntax, personally :) |
The short answer is that it provides a closure where you can create unique selector instances per component instance, so that the selectors memoize "properly" for that component. |
I mostly use this for component-scoped memoization of selector results. function mapState() {
const getSomeProp= createSelector(...);
return (state, props) => ({
someProp: getSomeProp(state, props),
});
} |
Right, that's the use case. What I'm saying is that the current doc page really doesn't actually describe how to do that or give examples. It hand-waves things, says, "you probably don't need to do what we just vaguely described anyway", and points to an old issue for examples. Since this is part of the API, it should be meaningfully documented. |
The current docs for the "factory function" syntax are not very clear, and also say that "most apps should never need this". We should rewrite that section, and also be sure to provide examples of using the factory function syntax.
For reference, discussion, and examples, see #279 , a Reddit comment I made with use cases and samples, and I think some of the articles in the Redux Performance section of my links list might discuss this.
The text was updated successfully, but these errors were encountered: