in my react-native app I use mobx for state management, I just noticed I'm getting a strict mode warning when changing the value of an observable object.
My error:
[MobX] Since strict-mode is enabled, changing (observed) observable values without using an action is not allowed. Tried to modify: UserStore@1.user
How I update mobx state
let copy = userStore.user;
copy.filterMood = 'newValue';
userStore.setUser(copy);
User store
import { makeAutoObservable } from "mobx";
import { makePersistable } from 'mobx-persist-store';
export class UserStore
{
constructor()
{
makeAutoObservable(this);
}
user = false;
setUser(payload)
{
this.user = payload;
}
}
import { UserStore} from '../stores/UserStore.js'
export const storesContext = React.createContext({
userStore: new UserStore()
});
configure({ enforceActions: "observed" });