react-redux-autoconnect

1.0.6 • Public • Published

react-redux-autoconnect

Convention over configuration for react-redux's connect()

Travis npm

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.

/react-redux-autoconnect/

    Package Sidebar

    Install

    npm i react-redux-autoconnect

    Weekly Downloads

    0

    Version

    1.0.6

    License

    MIT

    Last publish

    Collaborators

    • sargant