mobx-store.js
import {useLocalObservable} from 'mobx-react-lite'
function data() {
return {
array: [],
updateArray(args){
this.array = args
}
}
}
export const useMobxStore = () => useLocalObservable(data)
parent.js
import {useMobxStore} from 'blabla'
const ParentComponent({somevars}) {
const {data} = useFetch(someVars) <--- fetching hook
const mobxStore = useMobxStore()
mobxStore.updateArray(data)
console.log(mobxStore.array) <-----!!!! works!!
return <ChildComponent />
}
childcomponent.js
import {useMobxStore} from 'blabla'
function ChildComponent() {
const mobxStore = useMobxStore()
console.log(mobxStore.array) <--------!!!!!!! EMPTY!!!
return null
}
песочница тут
https://codesandbox.io/s/react-17-forked-i11jjc?fi...
в дочернем компоненте не работает console.log(store.array, "array")
почему ?