Using mobx to update data problems

Code:

let appState = observable({
    time: 11,
    do:function(){
        appState.time=12
    }
});
const App = observer(class app extends React.Component { 
componentDidUpdate(){
    console.log("1")
}
render(){
  return (<h2 onClick={appState.do}>Home{appState.time}</h2>;
}
  
})
ReactDOM.render(
  <App/>,
  document.body
);

does not actually update to data using action decorations, using action decorations:

let appState = observable({
     time: 11,
     do: action(function () {
     appState.time = 12;
})
    })

action is equivalent to setState. Why is action still updated without enabling it

Jun.08,2022

appState.time= returned by

observable is already a setter, and triggering reaction is normal

.

I guess you didn't turn on strict mode ( enforceActions )

Menu