Don't destructure
MobX observables are objects only. When destructuring, any primitive variables will remain at latest values and won't be observable anymore. Use boxed observables to track primitive values exclusively or preferrably pass a whole state object around.
// do NOT do this, it breaks reactivity
const {
userCateStore: { activeUserCate },
} = useRootStore()
const localStore = useLocalStore(() => ({
get dataSource() {
return activeUserCate
},
}))
In such case you can either wrap a whole component to observer
or destructure only down to nearest parent.
const { userCateStore } = useRootStore()
const localStore = useLocalStore(() => ({
get dataSource() {
return userCateStore.activeUserCate
},
}))
当前内容版权归 mobx-react 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 mobx-react .