-
Notifications
You must be signed in to change notification settings - Fork 55
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
State does not properly update components with multilevel object state #52
Comments
Thanks for reporting the issue. Would you mind reproducing the bug in codesandbox.io, so it is much easier for us to understand what is happening? On replacing the default // somewhere in your top/config import
import { defaults } from 'react-sweet-state'
import { produce } from 'immer';
defaults.mutator = (...args) => produce(...args); The you call const actions = {
increment: () => ({ setState }) => {
setState(draft => {
draft.count += 1;
});
},
}; |
So the issue happened when using setState and only returning a partial state. This was fixed when using immerjs to return the entire state. However I was unable to use your suggested mutator because the TypeScript check fails. I was able to do: const actions = {
increment: () => ({ getState, setState }) => {
const newState = produce(getState(), draft => {
draft.count += 1;
});
setState(newState);
},
}; |
Yeah, not sure how you can make TS happy as the signature of |
The typing issue seems to lie in const defaults: {
devtools: boolean;
middlewares: any;
mutator: <TState>(
prevState: TState,
partialState: Partial<TState> // I believe this second argument could be more flexible, but haven't been able to get the typing right yet
) => TState;
}; I tried with no luck: partialState: Partial<TState> | (<TState>(draftState: TState) => TState) |
I think I've found a solution to properly allow custom mutator types to be correct. Would you mind checking #53, try following the docs that I added and see if that works? |
The text was updated successfully, but these errors were encountered: