【发布时间】:2019-12-03 13:55:00
【问题描述】:
我正在使用带有 React 的 redux-saga。假设我正在从需要一些外部客户端计算的服务器获取一些数据。我的问题是把它们放在哪里。 我的传奇看起来是这样的:
function* someEffect(action){
try{
//removed none related stuff from the code.
const data = yield call(someRequestFucntionThatUsesAxios, requestparams);
if(data.status>=200&&data.status<300){
yield put({type:SUCCESS, payload:data.data)};
}
catch(err){
}
}
在上面的代码中data.data 需要一些计算(主要是基础数学)。现在,这些选项中的哪一个更有意义?
在我的连接组件componentDidUpdate 方法中处理这些计算。
收到后立即处理(在发送到减速器之前)。
(我知道reducer 不适合这种行为,但因为它不会杀死询问,)在我的reducer 中处理它。
【问题讨论】:
-
在axios中使用
transformResponse -
另一种方法是在
mapStateToProps内部进行计算并将结果作为组件的 prop 传递。将selectors与reselect一起使用可能有点矫枉过正,但对于大型应用程序来说是好的。
标签: reactjs react-redux redux-saga