Hello everyone I has a problem,
this is codeSilce.ts file
import { createSlice } from "@reduxjs/toolkit";
const codeSlice = createSlice({
name: "codeApply",
initialState: {
codeOTP: "",
token: "",
},
reducers: {
addcode: (state, action) => {
state.codeOTP = action.payload;
},
setToken: (state, action) => {
state.token = action.payload;
},
},
});
export const { addcode, setToken } = codeSlice.actions;
export default codeSlice.reducer;
this is reducer file
import codeSlice from 'app/slices/codeSlice';
const rootReducer = {
code: codeSlice
};
export type reducer = typeof rootReducer;
export default rootReducer;
this is store
import { configureStore } from "@reduxjs/toolkit";
import rootReducer from "./reducers";
const store = configureStore({
reducer: rootReducer,
});
export default store;
I use this in my file but it has some bug
import { reducer } from 'app/reducers'
const codeState = useSelector((state: reducer) => state.code)
const code = codeState.codeOTP; // wrong here
const token = codeState.token; // and here
this bug is
Property 'codeOTP' does not exist on type 'Reducer<{ codeOTP: string; token: string; }, AnyAction>'.
I don't know why this happening, I have console.log(codeState) but it is an object