I am Learning Redux Toolkit and using createEntityAdapter for a simple todo app. the problem is that I am getting errors whenever I try to access the todos from globalselectors or/and simple selectors of the todoAdapter.
I've created a CodeSandBox for this
This is the todoReducer code where I am setting
const todosAdapter = createEntityAdapter({
selectId: (todo) => todo._id,
});
const initialState = {
fetching: true,
error: null,
addingNew: false,
};
const todosSlice = createSlice({
name: 'todos',
initialState: todosAdapter.getInitialState(initialState),
reducers: {
pushNewTodo: todosAdapter.addOne,
addManyTodos: todosAdapter.addMany,
removeTodo: todosAdapter.removeOne,
editTodo: todosAdapter.updateOne,
},
extraReducers: { ... }
})
//* Errror in this line ,
export const globalTodosReducers = todosAdapter.getSelectors((st) => st.todos);
export const simpleTodosReducers = todosAdapter.getSelectors();
export const {
addTodo,
removeTodo,
toggleTodo,
editTodo,
clearTodos
} = todosSlice.actions;
export default todosSlice.reducer;
And when I want to use simpleSelectors , I get error in that also
// TodoApp.js
function TodoApp() {
.
.
.
// * Error in these lines
// const todos = globalTodosReducers.selectAll();
const todos = simpleTodosReducers.selectAll();
.
.
.
error is
Cannot read properties of undefined (reading 'ids')