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

Will useMemo replace reselect? #386

Closed
coryhouse opened this issue Dec 15, 2018 · 7 comments
Closed

Will useMemo replace reselect? #386

coryhouse opened this issue Dec 15, 2018 · 7 comments

Comments

@coryhouse
Copy link

@coryhouse coryhouse commented Dec 15, 2018

Is there anything reselect offers that useMemo can't handle?

@vinnymac
Copy link

@vinnymac vinnymac commented Dec 15, 2018

With only a cursory glance, I would assume that useMemo cannot replace reselect simply because useMemo is a hook and therefore will only work with functional components. While reselect works with any type of component.

As far as I know the original intent was to couple reselect with react-redux. Seeing as they plan on adding support for some kind of useRedux like functionality in react-redux I'd figure that could be coupled with useMemo eventually. I am pretty sure to get a real answer to your question we will have to wait to see what it is exactly react-redux creates in regards to a hook, and whether or not that works well with useMemo.

With that said, reselect can be used anywhere, as it has no dependencies. So if it was necessary to use with a theoretical new hook instead of connect(), it may be able to be repurposed for that use case.

@markerikson
Copy link
Contributor

@markerikson markerikson commented Dec 15, 2018

Reselect is indeed useful anywhere, and can be used totally independent of Redux. Really, its competition is libs like memoize-one, not useMemo().

For Redux usage, we recommend using selectors anywhere you access the Redux state tree, not just in mapState functions. That includes thunks, sagas, middleware, and so on. See my post Idiomatic Redux: Using Reselect Selectors for Encapsulation and Performance for more details.

@coryhouse
Copy link
Author

@coryhouse coryhouse commented Dec 15, 2018

Ha, I dunno what I was thinking. I know Hooks only work in React components. Sigh. Thanks for your patience and the excellent response guys! 👍

Closing. :)

@coryhouse coryhouse closed this Dec 15, 2018
@enoh-barbu
Copy link

@enoh-barbu enoh-barbu commented Apr 13, 2019

But in terms of using it within react apps, will there be any reasons for not replacing it with memo hooks?

@Kadrian
Copy link

@Kadrian Kadrian commented Nov 25, 2019

One stylistic difference is: with reselect and e.g. react-redux your component rerenders only when a selected/memoized value changes. With useMemo, the component renders anyways. Yes, you could create a wrapper / HOC that renders your component and use useMemo in there. That's essentially what react-redux's connect does. So well. To me at least, it seems to come down to a matter of individual taste

@pavan-shipmnts
Copy link

@pavan-shipmnts pavan-shipmnts commented Apr 13, 2020

But rendering is not the same as commit in react terms. For detailed explanation on the same
https://kentcdodds.com/blog/fix-the-slow-render-before-you-fix-the-re-render

@supnate
Copy link

@supnate supnate commented Sep 26, 2020

No, they are different. useMemo memorizes data per instance but reselect is global.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants