-
Notifications
You must be signed in to change notification settings - Fork 669
Selector with props does not make sense when defaultMemoize has cache size = 1 #66
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
Comments
Maybe. A couple of things to consider:
There is some discussion about this in the react-redux repo, and some more feedback would be welcome. |
@ellbee Thanks for the quick response!
My case is having 10-30 components of a particular kind on a page. Feeds in a post, Tweets in a stream, pictures/videos/media in a gallery are all similar examples. Its not as much as the state and props changing rapidly but getting a better understanding of how best to be able to re-use selectors for the same kind of components. According to my understanding, thats where the cache issue comes in (assuming the state and props for a single component won't change that much). What is the best practice when dealing with two or more of the same component on the page?
The parameters are objects (which I imagine is the worst case). The keys could be the |
How often do 2+ component instances benefit when their memoize cache are shared? I don't think alot. IMHO, cache size = 1 is already good enough, as long as the cache (lastArgs in defaultMemoize) belongs to a single component instance, not shared across instances. |
@compulim That would work as well - cache is specific to component-instance and not across instances. |
Trying to look at the problem by binding component instance with memorize function but it's not trivial. @ellbee can you give us some hints? |
Cool, thanks for looking into it. Did you check out the issue I linked? It is trying to solve the same thing by modifying react-redux slightly, but there is also the outline of an idea for solving it with |
Thanks @ellbee, I think it's the same issue. Let's centralize the discussion to reduxjs/react-redux#183. |
@ellbee what was the verdict on this? It looks like all the issues got closed, but no resolution was produced. |
Check this PR: reduxjs/react-redux#279 |
React Redux 4.3.0 allows per-instance memoization now. |
Assumption:
ReactRedux.connect
andreselect
to select data based onstate
andcomponent.props
Problem:
If the page have two or more component instances and their props are different, the memoize function (which has cache size = 1) will always cache miss.
This is because the memoize function is shared amongst all component instance, thus, component with different props will always invalidate each other.
Solution:
There are multiple solutions to this issue. I think memoize cache should bound to the component instance.
The text was updated successfully, but these errors were encountered: