Could mapStateToProps be an object?
See original GitHub issueI’m playing around with selectors, and most of my mapStateToProps
functions look like this:
const mapStateToProps = state => ({
isAuthenticated: selectors.isAuthenticated(state),
isSomethingElse: selectors.isSomethingElse(state),
});
Since I always pass on the state, would it be okay to do the same thing as mapDispatchToProps
does, and just allow sending an object of functions? Like so:
const mapStateToProps = {
isAuthenticated: selectors.isAuthenticated,
isSomethingElse: selectors.isSomethingElse,
};
Then, connect
could do the work required to call each of these with the state.
I’d be happy to submit a PR doing this - but what are your thoughts? I’m sure there’s a reason the API is the way it is 😃
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:13 (8 by maintainers)
Top Results From Across the Web
Connect: Extracting Data with mapStateToProps
Your mapStateToProps function should return a plain object that contains the data the component needs: Each field in the object will become a ......
Read more >mapStateToProps must return an object. Instead received ...
Your state appears to be a map from immutable.js, while mapStateToProps is supposed to return an object, as your error message says. Try...
Read more >You Might Not Need The mapDispatchToProps Function
First, a mapStateToProps function that plucks pieces of state out of Redux and assigns them to props that your React component will use....
Read more >What is mapStateToProps in Redux?
The mapStateToProps function is wrapped in a connect function provided by the React-Redux library. The connect function will allow four ...
Read more >Manage state with React Hooks
You can use hooks to subscribe to the Redux store and dispatch actions, ... Implement mapStateToProps to have access to the state object...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Part of me still kinda wants do to this, but I’ll go along with Tim and say it’s not worth it to build it in.
I’m willing to potentially reconsider this as long as we keep it narrowly scoped in behavior and implementation.
No factory functions. No nesting.
I can see two useful forms:
Both are doable if we keep the behavior limited to basically what @jchook showed. Question is, whether there’s enough benefit for including that functionality.
Tweeted this question: https://twitter.com/acemarke/status/1087568080052596736
I’ll reopen this issue for the sake of discussion.