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 · 8 comments
Closed

Will useMemo replace reselect? #386

coryhouse opened this issue Dec 15, 2018 · 8 comments

Comments

@coryhouse
Copy link

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

@vinnymac
Copy link

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 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

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. :)

@enoh-barbu
Copy link

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 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

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 commented Sep 26, 2020

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

@mrdulin
Copy link

mrdulin commented Apr 17, 2024

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

I'm curious whether the memory usage of useMemo() will be greater than that of selector if there are a lot of instances.

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

8 participants