I'm finding my way around the Redux echosystem, and I came across the following sutuation: Suppose I have a React component which should be connected to a redux state part using a selector, but this part does not exist yet (undefined). So, when running it I get a "get on undefined" error. Is it possible to somehow define and connect the selector to the component, even though the state part does not exist yet?
I'm using reselect for creating the selector, this is a workaround I've used to avoid throwing the error:
import { createSelector } from 'reselect';
const selectLogin = (state) => state
const loginDataSelector = () => createSelector(
selectLogin,
(authState) => authState.get("auth")?
authState.get("auth").get('loginData'):undefined
);
export {
loginDataSelector
};
By this way, the selectLogin
selector seems to monitor the entire state tree. Is there a better way to do this, or is there a best practise for selectors with an undefined (=not set yet) state part?