reselect icon indicating copy to clipboard operation
reselect copied to clipboard

Can't pass props in selectors

Open vasa-chi opened this issue 11 years ago • 12 comments

react-redux supports passing props to select. Currently reselect only passes state. Is it possible to add props to selector functions?

vasa-chi avatar Aug 06 '15 14:08 vasa-chi

I'm not sure that the new react-redux api for the connect decorator is going to support this. Check out this PR

ellbee avatar Aug 06 '15 18:08 ellbee

Huh. That would be unfortunate... Maybe @gaearon can clarify?

vasa-chi avatar Aug 07 '15 12:08 vasa-chi

Seems that there will be an additional argument for @connect decorator for using props to further filter the state. So I guess that yes, this api will get deprecated.

vasa-chi avatar Aug 07 '15 13:08 vasa-chi

Confirmed as gone in the release notes for react-redux v.0.5.0

ellbee avatar Aug 07 '15 19:08 ellbee

It looks like this added back in react-redux. Can we get it back in this package?

scottcorgan avatar Aug 19 '15 18:08 scottcorgan

Yep, I guess we should look into this now

ellbee avatar Aug 19 '15 18:08 ellbee

Any time frame on this? Attempted to jump in on a fork, but didn't know if changes were coming soon for a 1.0.

scottcorgan avatar Aug 20 '15 18:08 scottcorgan

Funnily enough, I was just looking at it. Did you have a plan? I'm wondering how the dumb default memoize and its reference equality is going to work with the props. I don't recall how the props are handled inside react. I guess if the prop object is mutative and has a stable reference for the lifetime of the component or it is recreated entirely on each render then we might have problems?

I think that the API might change slightly in the next version, possibly allowing the user to specify a memoization function in createSelectorCreator and allowing variadic depencies. I just started exploring this in my fork here if you'd like to have a look.

ellbee avatar Aug 20 '15 19:08 ellbee

I guess if the prop object is mutative and has a stable reference for the lifetime of the component or it is recreated entirely on each render then we might have problems?

Props object is new every time. It's considered immutable.

gaearon avatar Aug 20 '15 22:08 gaearon

Okay, I just finally started using reselect in a project and ran into this one. So basically we want to parameterize the select expression with an additional object that should be passed down the select chain, right? And we should be able to express when we consider this object unchanged, so that we can make use of caching.

faassen avatar Aug 31 '15 15:08 faassen

Take a look at #35. We've had a bit of a discussion about this there

ellbee avatar Aug 31 '15 15:08 ellbee

Address in the 1.0.0 release

ellbee avatar Sep 09 '15 20:09 ellbee