-
Notifications
You must be signed in to change notification settings - Fork 5
Use of routeNodeSelector() with mapStateToProps() #14
Comments
You can do this if you're using the object rest spread transform:
Without the transform:
The very last example at the bottom of the README shows how this was reached. |
You can compose const mapStateToProps = (state) => {
const routeSelector = routeNodeSelector('about');
return (state) => ({
...routeSelector(state),
progress: state.user.progress
});
}; |
hmm, I want to know one more thing:
what does the 'user' key do? I thought if I had user.list, user.edit etc etc, it'd give me only list, edit etc on route.name, but that doesn't seem to be the case, or am I doing it wrong? Or did I misunderstood routeNodeSelector? |
Your code sample doesn't leverage memoization because it creates a new selector each time, so at a result it behaves like a normal selector. It should be: const mapStateToProps = state => {
const selector = routeNodeSelector('user')
return state => ({
...selector(state),
progress: state.user.progress
})
}) Do you have more context around your use case? |
ahh, got that part, as of now I'm having to do something like: So I have to extract the |
Also I imagine you have another route node selector (or component bound to the route) above your |
yes, the index level, index has stuff like:
and so on. On index page, I do routeNodeSelector("") and get the route, and I do split(".")[0], On UsersPage I do routeNodeSelector("user") then do a split(".")[1] (after handling undefined cases), then render List, Edit or Create page depending on segment. |
Hi, I'm implementing the router in a standard react-redux app.
So far connecting component to router states was easy following the examples, for instance:
but now I'd like to, in addition and the same component, retrieve a slice of the redux state using a classic
mapStateToProps()
function:What would be the best to achieve this? The examples show no such use case.
Thank you again!
The text was updated successfully, but these errors were encountered: