-
Notifications
You must be signed in to change notification settings - Fork 56
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
Accessing previous props in onUpdate? #131
Comments
Is that because you might not want to trigger the update function at all or just diffing individual props? |
Sometimes so, sometimes so, but mostly diffing on individual props. Agree that providing
|
This is something that one must do frequently to be able to make the store communicate with the outside world. This is another common pattern we use a lot;
This similar kind of pattern is almost a best practice to keep the store consistent with the outside via the update method. Although I think this is an area that RSS might find a common solution/pattern/tool, I'm not sure the action creator params is the best place to do this.
Also, there are potential use cases where the consumer may want to use an already existing action with optional parameters in place of the update function and introducing pre-defined parameters there may prevent that. So it does not map "well" with the action creator parameters, at least in my opinion. Especially considering the little benefit. Still, I really think the update/init actions (or rather making multiple stores communicate) is a pain point which may need further thought from an RSS perspective. Exposing the comparison function might be an thing indeed. |
I'm happy to say that from v2.7.0 prev/next props are available on the new const Store = createStore({
initialState,
actions,
containedBy: TodosContainer,
handlers: {
onInit: (nextProps, prevProps) => ...
},
}); |
Hi team,
I occasionally find myself wanting to make more fine-grained decisions about what to do in
onUpdate
, requiring me to understand how exactly the props changed. However, as I only have access to the current props, I have to put the props into thestate
for later comparison. That seems not overly elegant to me. Would it be possible to make the previous props accessible inonUpdate
?The text was updated successfully, but these errors were encountered: