Slightly related to the question in the FAQ: Can I use Reselect without Redux?
One advantage reselect has over other common memoization libraries is that most don't support caching multiple arguments out of the box. For example to enable multipe args for Lodash memoize, you have to pass your own resolver function, which resolves your arguments into a single key anyways.
I've been exploring using reselect as a general purpose selector, attached to React components as a class property. Example:
class Foo extends React.Component {
getFooSelector = createSelector(
[args => args.foo, args => args.bar, args => args.baz],
(foo, bar, baz) => { /* something expensive */ }
);
someFunction() {
const foo = getFooSelector({ foo: something, bar: something, baz: something });
}
}
I was wondering, are there any gotchas or hidden costs of doing this? So far, it's been working very well for my use case. Thank you!
That's absolutely fine. Reselect was definitely written with the intent of being used with Redux, but it is indeed a general-purpose lib that has no actual ties to Redux. You should feel free to use it anywhere in your app.
Thank you!
Most helpful comment
That's absolutely fine. Reselect was definitely written with the intent of being used with Redux, but it is indeed a general-purpose lib that has no actual ties to Redux. You should feel free to use it anywhere in your app.