在mobx动作中返回价值是一种好习惯吗?

时间:2019-08-27 14:49:30

标签: javascript reactjs mobx mobx-react

我想知道在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>
)

}
}

0 个答案:

没有答案