redux-spy
v1.0.1
Published
A higher order component decorator to spy on Redux state with subscribing to it
Downloads
6
Maintainers
Readme
Redux Spy
redux-spy
works like react-redux
's connect()
decorator, except that, rather than subscribe
to changes in the Redux store, which causes a rerender, it gives its wrapped component a function
with which to query specific slices of the Redux store.
It works by using a non-rendering child component that is subscribed to the Redux store.
Screencast
This is a screencast of the example app running.
Why???
This will not be a hugely popular library because it is only useful in rare edge cases.
I am currently working on a redesign of redux-form
,
which contains a large outer component, that is very expensive to rerender, but that
occasionally (e.g. form submit) needs access to state in Redux that changes on every single
keystroke. Rather than rerender the whole form every time, redux-spy
will allow my large
component to spy on the Redux state only when it needs to.
API
reduxSpy(mapStateToKeys)
mapStateToKeys
is very similar tomapStateToProps
that you would give toconnect()
, except it doesn't accept anownProps
second parameter.
Props provided to your decorated component
spy(key:String)
: Function
A function to call to get the corresponding value from the Redux state. The
key
parameter much match on the keys in the map returned frommapStateToKeys
.