I already have some prior experience using React and Redux with JavaScript, but I just started a project using TypeScript. While reading the documentation for redux-toolkit, I found out about the idea of creating selectors to facilitate getting the data you need from the state tree.
Now, from the official documentation, the guidelines to write a selector in a slice require you to already know how the store will name this slice. For example, from the Create React App redux-typescript template:
export const selectCount = (state: RootState) => state.counter.value;
Notice that the counter from state.counter is only named in the root reducer file:
export const store = configureStore({
reducer: {
counter: counterReducer,
},
});
This seems like a really bad idea to me, since if I change the name of the slice in the root reducer, I'll need to go back to the slice itself and update this new name there too. Also, it seems like an overkill to get all the RootState when I don't need anything from another part of the state.
So, can I write a selector that only sees the state of the current slice, and let the combineReducers function to deal with its address? Example:
export const selectCount = (state: CounterState) => state.value;
If not, is there a better way to read a specific value from the state without needing to know the exact structure of the store?