Redux CombineReducers is broken

Recently I have started using react redux. It’s amazing how complex React/Redux makes even the simplest task.

I needed to pass an environment value through to the client side rendered ui. This was to allow the component to vary by environment – something essential in a dev -> qa -> preprod -> live pipeline.

You need to pass this into the store and map it out into the state of your component. All of the documentation and examples seem to care about is state mutation. The trivial case is overlooked.

The app that I am working on has multiple reducers that are combined with CombineReducers. This has the interesting side effect of dropping any state that is not included in a reducer.

This is not accidental it actually warns you (cryptically) that it is doing it.

I solved this for now by creating an idempotentReducer that simply returns the state. This is not a good long term solution.

The documentation on CombineReducers does state that it is intended for simple cases. I can’t imagine why passing through static state is not the simplest case.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s