react-native - Multiple Item Objects In Redux Store
问题描述
I have following store on Redux:
{
"forgotPassword": {
"item": {
"error": "ok",
"params": {
"email": "test@asd.com"
},
},
"fetchEmail": {
"loading": false,
"error": null
},
"fetchChangePassword": {
"loading": false,
"error": null
}
},
"_persist": {
"version": -1,
"rehydrated": true
}
}
But I want my store like this:
The difference is item
object is there for both fetchEmail
and fetchChangePassword
objects.
{
"forgotPassword": {
"fetchEmail": {
"item": {
"error": "ok",
"params": {
"email": "test@asd.com"
},
},
"loading": false,
"error": null
},
"fetchChangePassword": {
"item": {
"error": "ok",
"params": {
"email": "test@asd.com"
},
},
"loading": false,
"error": null
}
},
"_persist": {
"version": -1,
"rehydrated": true
}
}
This is my file structure;
Store
--ForgotPassword
----FetchEmail.js
----FetchChangePassword.js
----index.js
--index.js
//FetchEmail.js
export default {
initialState: buildAsyncState('fetchEmail'),
action: buildAsyncActions('forgotPassword/fetchEmail', fetchEmailService),
reducers: buildAsyncReducers({
errorKey: 'fetchEmail.error',
loadingKey: 'fetchEmail.loading',
}),
}
//FetchChangePassword.js
export default {
initialState: buildAsyncState('fetchChangePassword'),
action: buildAsyncActions('forgotPassword/fetchChangePassword', fetchChangePasswordService),
reducers: buildAsyncReducers({
errorKey: 'fetchChangePassword.error',
loadingKey: 'fetchChangePassword.loading',
}),
}
//ForgotPassword/index.js
import FetchEmail from './FetchEmail'
import FetchChangePassword from './FetchChangePassword'
const sliceInitialState = {
item: {},
}
export default buildSlice('forgotPassword', [FetchEmail, FetchChangePassword], sliceInitialState).reducer
I have tried following changes:
Changed item objects accordingly.
//ForgotPassword/index.js
const sliceInitialState = {
itemEmail: {},
itemChangePassword: {},
}
Added following to my reducers
:
//FetchFetch.js
itemKey: 'fetchChangePassword.itemFetch',
//FetchChangePassword.js
itemKey: 'fetchChangePassword.itemChangePassword',
How can I add item
object to my reducers separately?
解决方案
推荐阅读
- javascript - React-Native Realm TypeError:Reflect.construct 要求第一个参数是构造函数 - 错误
- sql-server - Powershell SQL Server 存储过程备份
- excel - 运行时错误“1004”对象“_Worksheet”的方法“范围”失败
- django - 在 Django 中,为一天内的两个日期时间过滤查询集
- edsdk - EDSDK Live view 问题使用 canon 示例
- javascript - JS函数odblclick事件
- angular - 图像未立即以角度显示
- docker - docker swarm:复制服务和全局服务之间的区别
- sql - 根据其他列中的条件选择值对 - PostgreSQL
- python - 如何根据 Matplotlib 中的属性更改线条的颜色?