[英]How can I setup my Redux Initial state as an Object, and then properly sync it with my reducer functions?
[英]How can I put my initial state into my redux store?
我正在尝试使用 redux 制作登录功能。 问题是我无法弄清楚如何使用我存储用户信息的初始状态。
import { configureStore } from '@reduxjs/toolkit'
import { postListReducer, postDetailsReducer } from './reducers/postReducers'
import { userLoginReducer } from './reducers/userReducers'
const store = configureStore({
reducer: {
postList : postListReducer,
postDetails : postDetailsReducer,
userLogin : userLoginReducer,
},
})
const userInfoFromStorage = localStorage.getItem('userInfo') ?
JSON.parse(localStorage.getItem('userInfo')) : null
const initialState = {
userLogin : {userInfo: userInfoFromStorage}
}
export default store
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.