reactjsmobxmobx-reactmobx-react-lite

What's the difference between @computed and @action in MobX?


What's the difference between @computed and @action in MobX?

They both are functions, so what is difference between them?


Solution

  • @computed is used when the function will 'compute' the return value from existing information.

    @action is used for functions that will change to the existing information (state), and prompts 'observers' to access the latest version of the relevant 'observable(s)'.