mobxjs / mobx-react

React bindings for MobX
https://mobx.js.org/react-integration.html
MIT License
4.85k stars 349 forks source link

Confused about useLocalStore get for computing #770

Closed jackple closed 5 years ago

jackple commented 5 years ago

When I spread to activeUserCate from useRootStore(), console is not working

const { userCateStore: { activeUserCate }, chatStore } = useRootStore()
const localStore = useLocalStore(() => ({
    get dataSource() {
        console.log(1)
        return activeUserCate
    }
}))

But when I spread activeUserCate from userCateStore in get, it works

const { userCateStore, chatStore } = useRootStore()
const localStore = useLocalStore(() => ({
    get dataSource() {
        console.log(2)
        const { activeUserCate } = userCateStore
        return activeUserCate
    }
}))

Somebody know why?

danielkcz commented 5 years ago

It's expected behavior. Thanks for the examples though, used them in docs right away :)

https://mobx-react.js.org/state-destruct

lock[bot] commented 4 years ago

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.