Skip to content
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

Closed
markerikson opened this issue Sep 27, 2017 · 4 comments
Closed

Improve docs for "factory function" syntax #797

markerikson opened this issue Sep 27, 2017 · 4 comments

Comments

@markerikson
Copy link
Contributor

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.

@timdorr
Copy link
Member

timdorr commented Sep 27, 2017

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 :)

@markerikson
Copy link
Contributor Author

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.

@jimbolla
Copy link
Contributor

I mostly use this for component-scoped memoization of selector results.

function mapState() {
  const getSomeProp= createSelector(...);
  return (state, props) => ({
    someProp: getSomeProp(state, props),
  });
}

@markerikson
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants