【发布时间】:2016-11-08 11:04:40
【问题描述】:
我正在使用 react-native + redux + immutable 构建一个 Android 应用程序
我的应用是这样构建的
/src
-/components
-/actions (where I have action types and actions)
-/reducers
-/api (I'm not sure if I'm doing this right)
好的,所以我有一个操作需要使用 fetch 进行 API 调用,如下所示:
import * as types from './casesTypes'
export function getCases() {
return {
type: types.GET_CASES
}
}
这是case reducer:
const initialState = fromJS({
isLoading: false,
cases: null
})
export default function cases(state = initialState, action = {}) {
switch(action.type) {
case types.REQUEST_CASES:
return state.set('isLoading', true)
case types.RECIVE
return state.set('cases', //set here the array that I recive from api call)
default:
return state
}
}
所以,问题是我真的不明白,我应该在哪里进行 API 调用,以便在 reducer 中我可以将我的初始状态与我从 API 调用中收到的内容合并?
【问题讨论】:
标签: reactjs react-native redux react-redux