reselect icon indicating copy to clipboard operation
reselect copied to clipboard

reconsider allowing selectors to take arguments

Open jwoudenberg opened this issue 10 years ago • 3 comments

So I read the issues related to selectors taking no arguments (#18, #38, #59) and I understand the reasoning behind it: that if you feel the need to create a selector with a dynamic argument, probably that argument should be in your store state somewhere.

Only I don't believe that's necessarily true. In a project I'm working on we keep the router state in the router itself and don't jump through extra hoops to sync this with the store state. I think this too is a pretty well established pattern. It would be great to be able to pass the router state into a selector as an argument.

I'm curious to hear your thoughts :smile:.

jwoudenberg avatar Sep 01 '16 13:09 jwoudenberg

When using connect, component props are passed as the second argument to the selector. This allows you to use the pattern referenced in your link.

More details here: https://github.com/reactjs/reselect#createselectorinputselectors--inputselectors-resultfunc

ellbee avatar Sep 01 '16 20:09 ellbee

I should have found that myself, that works nicely. Thanks for your reponse!

jwoudenberg avatar Sep 02 '16 06:09 jwoudenberg

@ellbee what if you don't want to couple your component code to your selector code? What's to stop someone from passing in a custom props object there? Isn't the essentially the same as passing args?

CharlieEarnup avatar Aug 09 '18 21:08 CharlieEarnup