In most cases, I use observable
with observer()
in React components instead of React's state.
However, to use React's state with MobX is anti-pattern? For example, is this below anti-pattern?
@observer
class Counter extends React.Component {
state = {
count: 0
};
render() {
return <button onClick={this._handleClick}>{count}</button>
}
_handleClick = () => {
this.setState(prev => {count: prev.count + 1});
};
}
I know it can be replaced with observable
but I wonder if it is an anti-pattern.
Or, is it better to use observable
than to use React's state in observed components? if so, why?