Skip to content

A higher order component decorator to read from a Redux store without subscribing to all its changes

License

Notifications You must be signed in to change notification settings

erikras/redux-spy

Repository files navigation

Redux Spy

NPM Version NPM Downloads Build Status codecov.io

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.

screencast

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 to mapStateToProps that you would give to connect(), except it doesn't accept an ownProps 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 from mapStateToKeys.

About

A higher order component decorator to read from a Redux store without subscribing to all its changes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published