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

Selector parameter from React Router #82

Closed
gerhardsletten opened this issue Feb 15, 2016 · 3 comments
Closed

Selector parameter from React Router #82

gerhardsletten opened this issue Feb 15, 2016 · 3 comments

Comments

@gerhardsletten
Copy link

Hi, I try to use create a selector with the param from React Router for a Master > Detail application, but it looks like it recalculate it every I go into the Detail-view. Should not this be cached?

(when I return to the Masterview, the id-param of the router will be undefined, but it should equal when I re-enter the Detail-view (and viewing an item with the same ID)

import {createSelector} from 'reselect'

const getRouterID = (state) => state.router.params.id
const getItems = (state) => state.items // array

export const getSelectedBook = createSelector(
  [getRouterID, getItems],
  (id, items) => {
    return items.filter((item) => {
      return item.id === id
  }
)
@gerhardsletten gerhardsletten changed the title Selector paramter from React Router Selector parameter from React Router Feb 15, 2016
@ellbee
Copy link
Collaborator

ellbee commented Feb 16, 2016

Hi @gerhardsletten, that should work fine. If you can provide a runnable example of this not working I'll take a look.

@gerhardsletten
Copy link
Author

It works, but should not the items.filter... be cached?

In this application I have this list of items, and when I first enter an item it is runned, I then returned back to the list, but when I reenter the same item (same id) the filter-code is runned again. This is where I thought reselect should cache the returned content..

@ellbee
Copy link
Collaborator

ellbee commented Feb 16, 2016

Yes, we meant the same thing, sorry if I wasn't clear. By "it should work" I meant it should cache when the arguments haven't changed.

Have you checked this question from the FAQ?

https://github.com/reactjs/reselect#q-why-is-my-selector-recomputing-when-the-input-state-stays-the-same

I will need to see an example where Reselect is not behaving as you expect if I am going to be able to help further.

@ellbee ellbee closed this as completed Feb 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants