提问人:Ahmad 提问时间:11/26/2022 更新时间:11/26/2022 访问量:35
redux thunk 获取 API
redux thunk fetch API
问:
我正在开发一个 React 应用程序,该应用程序使用组件级状态,我想重新定义该应用程序并转换为 redux thunk,但我被困在 redux 初始状态,如何管理有人可以看看。
const [data, setData] = useState([]);
const [userData, setUserData] = useState([]);
const [selections, setSelections] = useState([]);
const [demos, setDemos] = useState([]);
const [labels, setLabels] = useState([]);
const [populatedDepartments, setPopulatedDepartments] = useState([]);
const [populatedlocations, setPopulatedlocations] = useState([]);
const [departmentCascadePath, setDepartmentCascadePath] = useState([]);
const [locationCascadePath, setLocationCascadePath] = useState([]);
const account = (state = {data: []}, action) => {
switch(action.type) {
case "FETCH_ACCOUNT_REQUEST":
return {
loading: true,
}
case "FETCH_ACCOUNT_SUCCESS":
return {
loading: false,
data: action.payload.data
}
case "FETCH_ACCOUNT_FAILED":
return {
loading: false,
error: true,
message: action.payload
}
default:
return state
}
}
export default account
我想将本地状态存储到 redux 中,但我卡在这一点上
答: 暂无答案
评论