Redux middleware for wrapping store in a Proxy to help with complex nested states.
You need to import
the module and then include it in the applyMiddleware
invocation.
import {createStore, applyMiddleware} from 'redux';
import {nest} from 'redux-nest';
// ...
const createStoreWithMiddleware = applyMiddleware(nest)(createStore);
From there any data that passes through the store will be wrapped in a Proxy
that will prevent undefined
from causing issues when you chain properties.
In the following case, even if person
is undefined it will still succeed and simply print nothing:
<label>
{store.person.name}
</label>
As the data is wrapped in a Proxy
you cannot do the usual check of typeof x === 'undefined'
because now x
is an instance of Proxy
— to allow you to check if x
is undefined
, redux-nest
provides two functions.
import {isDefined, isUndefined} from 'redux-nest';
// ...
if (isDefined(x)) {
}