Redux toolkit combineReducers problem.:Store does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose
Solution 1:
There's a few issues here:
-
configureStore
automatically callscombineReducers
for you, so you don't want to do that directly. -
configureStore
'sreducer
object needs reducers, but you're passing it a slice. (The slice contains a reducer, but the slice itself is not a reducer.) - Your
setValue
is returning a new object, but RTK uses Immer, so you should mutate the state passed into the function and not return anything.
In the end your code should look like this:
// configureStore.js
import { configureStore } from "@reduxjs/toolkit";
import pokemonSearchSlice from "./slices/pokemonSearch";
const store = configureStore({
reducer: {
pokemon: pokemonSearchSlice,
},
});
export default store;
// slices/pokemonSearch.js"
import { createSlice } from "@reduxjs/toolkit";
const pokemonSearchSlice = createSlice({
name: "pokemonSearch",
initialState: {
searchInputValue: "",
},
reducers: {
setValue: (state, action) => {
state.searchInputValue = action.payload;
},
},
});
export const { setValue } = pokemonSearchSlice.actions;
export default pokemonSearchSlice.reducer;