lundi 3 septembre 2018

Redux/typescript selectors for optional values best practices?

So I have a key in my redux state roomId that is only undefined for a short amount of time. After that it will always be defined.

Now the problem is that my state looks like this:

interface State {
  roomId?: string;
}

And my selector

export const getRoomId(state: State) => state.roomId;

But the problem is that in all my code I need to check if the roomId returned by the selector is defined or not. A bit annoying to do this in all places.

Any other suggestions to avoid this?

I could throw an error in the selector, but in this case doesn't sound too right as well.

Aucun commentaire:

Enregistrer un commentaire