Closed chentianxin closed 5 years ago
You are missing an observer around the component. The useObserver
is not enough because it cannot see changes to observables. Another way is to avoid destructuring and accessing through store within useObserver
boundary should work.
import {useLocalStore} from 'mobx-react-lite';
const useChatStore = () => { const store = useLocalStore(() => ({ chatList: [], add(val) { this.chatList.push(val); }, }));
return store; };
export default useChatStore;
hatStore} = useRootStore(['chatStore']); const list = chatStore.chatList; const add = chatStore.add; useEffect(() => { let timer = setInterval(() => { add(timer); }, 1000); }, []); console.log(JSON.stringify(chatStore));
return useObserver(() => ( <>...</> )
After the state changes here, the view will be re-rendered.
Sorry, but prepare a CodeSandbox example if you need further help. Also, learn how to format text as a code in GitHub, this is horrible to read.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or questions.