【发布时间】:2022-06-11 14:02:21
【问题描述】:
我有一个输入字段,我尝试在其中传递一些信息,然后再转到单独的页面。我的问题是 Redux 状态没有改变,但控制台显示值正在正确传递。我假设我的 Slice 有问题,但我相信我正确传递了有效载荷。我的 Redux 切片看起来像:
import { createSlice } from "@reduxjs/toolkit";
export const walletSlice = createSlice({
name: "wallet",
initialState: {
wallet: "xxx-xxxx-xxx-xxxx",
},
reducers: {
setWalletAddress: (state, action) => {
state.value = action.payload;
},
},
});
export const { setWalletAddress } = walletSlice.actions;
export default walletSlice.reducer;
虽然我的 from 组件看起来像:
import { setWalletAddress } from "../../redux/wallet";
import { useDispatch } from "react-redux";
export default function AddressForm() {
return (
const dispatch = useDispatch();
const handleChangeWallet = (event) => {
dispatch(setWalletAddress (event.target.value));
console.log(event.target.value);
};
<React.Fragment>
<TextField
onChange={handleChangeWallet}
label="Wallet address"
/>
</React.Fragment>
);
}
我的商店看起来很标准:
export default configureStore({
reducer: {
wallet: walletReducer,
},
});
【问题讨论】:
标签: javascript reactjs redux material-ui