Skip to content

Will useMemo replace reselect? #386

Description

@coryhouse

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

Activity

  1. vinnymac commented on Dec 15, 2018

    @vinnymac

    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.

  2. markerikson commented on Dec 15, 2018

    @markerikson
    Contributor

    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.

  3. coryhouse commented on Dec 15, 2018

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

  4. enoh-barbu commented on Apr 13, 2019

    @enoh-barbu

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

  5. Kadrian commented on Nov 25, 2019

    @Kadrian

    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

  6. pavan-shipmnts commented on Apr 13, 2020

    @pavan-shipmnts

    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

  7. supnate commented on Sep 26, 2020

    @supnate

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

  8. mrdulin commented on Apr 17, 2024

    @mrdulin

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions