Redux store shape depending on another state value

Viewed 26

I am developing an app using React and Redux which has, over time, evolved two modes, which have different state shapes. The modes are mutually exclusive, and the user selects the mode when the app loads. The mode is then fixed, and cannot be changed by the user.

The store has simply accumulated state relating to these two modes, but this seems incorrect - the mutual exclusivity of the two modes should surely be reflected in the store shape, and it should only contain state relating to the active mode.

Clearly some kind of conditional logic is required, but I'm not sure how to implement this - I mean this must be a fairly common pattern, but I can't seem to find Redux-based examples. There is a mode state entry, and it's the value of this that would determine the store shape. So one part of the store shape is itself dependent on another part of the store state.

I breifly considering having multiple stores, but then dismissed the idea.

0 Answers
Related