我正在使用 React-Redux 的 React Hooks 實(shí)現(xiàn)。下面是我的代碼流程。由于某種原因,我傳入的任何值dispatch(fuction(value))都沒有在我的減速器中檢測到。我想不通。src/components/categories/selectCategory.tsx import React from 'react'; import {useDispatch} from 'react-redux'; import {setCategory} from '../../store/actions'; const selectCategory = (name: string) => { dispatch(setCategory(name)); // ex: name = 'algebra' };存儲/操作/index.tsexport const setCategory = (name) => ({ type: 'SET_CATEGORY', name: name});存儲/reducers/index.tsimport {combineReducers} from 'redux';import category from './category';const app = combineReducers({ category});export default app;存儲/reducers/category.tsconst initialState = { name: 'calculus'};const category = (state = initialState, action) => { switch (action.type) { case 'SET_CATEGORY': return {name: state.name}; // outputs 'calculus' default: return state; }};export default category;我敢肯定,我缺少一些小細(xì)節(jié)。
React Redux 不更新狀態(tài)
尚方寶劍之說
2022-01-07 16:13:01