我想知道在mobx操作中返回值是否是一个好习惯
像这样
@observable data = null
@action async fetchingSomeData() {
this.data = service.fetchingdatas()
return this.data
}
然后在我的componentDidMount挂钩中检索它
@observer
export default class SomeClass extends React.Component
async componentDidMount() {
const {store} = this.props
const data = await store.fetchingSomeData()
//do something with data or a condition verification (if(data.someOtherData for instance ?)
}
render() {
const {store } = this.props
return (
<div>dataFormaterfunction(store.data)</div>
)
}
}