react-redux-autoconnect
v1.0.6
Published
Convention over configuration for react-redux's `connect()`
Downloads
3
Readme
react-redux-autoconnect
Convention over configuration for react-redux's connect()
Usage
autoConnect(Component, [options])
Like connect()
, but looks for static methods called mapStateToProps
,
mapDispatchToProps
, and mergeProps
on the passed Component
, instead of
passing them manually.
For how to use mapStateToProps
, mapDispatchToProps
, and mergeProps
, read
the react-redux documentation
The optional options
argument is also passed to connect()
as the fourth argument.
Why?
So you can now keep everything wrapped up in a single class:
import autoConnect from 'react-redux-autoconnect'
class Foo extends React.Compoment {
render () {
return (
<div>Hello {this.props.name}!</div>
)
}
static mapStateToProps = (state) => ({
name: state.name
})
}
export default autoConnect(Foo)
This is stupidly simple code and you should be ashamed
I know, but I was fed up of writing the same utility function over and over.