gpt4 book ai didi

javascript - Redux 的状态是 promise

转载 作者:行者123 更新时间:2023-11-28 16:59:44 24 4
gpt4 key购买 nike

我一直在尝试让工作成为一个非常简单的 redux 存储,但是当尝试访问它时,它显示 inPromise

已经尝试使用 console.log() 进行调试,但我无法找到错误

token = undefined state = {auth: Promise} auth: Promise {<resolved>: {…}} __proto__: Object


const mapStateToProps = (state) =>{ console.log(state) return{ isAuthenticated:state.auth.token !== null, token:state } }

创建 reducer

const authReducer = async (state =INITIAL_STATE, action) => { switch (action.type){ case actionTypes.AUTH_START: return authStart(state, action); case actionTypes.AUTH_SUCCESS: return authSuccess(state, action); case actionTypes.AUTH_FAIL: return authFail(state,action); case actionTypes.AUTH_LOGOUT: return authLogout(state,action); default: return state; } }

和根 reducer

export default combineReducers({ auth: authReducer });

和商店创建

const middlewares = [logger, thunk] const store = createStore(rootReducer,applyMiddleware(...middlewares))

最佳答案

async总会返回一个 promise 。您没有理由在 reducer 上安装一个并且将其删除。

const authReducer = (state =INITIAL_STATE, action) => { ...etc }

关于javascript - Redux 的状态是 promise ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57892825/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com