react-redux-simple-autoconnect

1.0.0 • Public • Published

react-redux-simple-autoconnect

Build StatusCoverage Status

Features

  • Use propTypes definition to auto connect actions/data to component
  • Use mergeProps/options of the real connect function

How it works ?

The library use propTypes declared in the Component to link state properties or actions (dispatch is automatically added) to Component.

The library will bind properties by listing state and actions object keys.

API

autoConnect([getStates], [getActions], [mergeProps], [options])(ComponentClass)

autoConnect is the default function of the library.

This function is built on top of connect from react-redux.

Arguments

  • getStates(state, ownProps) : Array[state]: This function must return an array of states. If function is not provided, null will be given to connect in the mapStateToProps place.

Parameters:

Name Description
state Redux store state like in connect in the mapStateToProps
ownProps The props passed to the connected component
  • getActions(ownProps) : Array[actions]: This function must return an array of actions objects. If function is not provided, null will be given to connect in the mapDispatchToProps place.

Parameters:

Name Description
ownProps The props passed to the connected component
  • mergeProps() : Same function as in the connect official API.

  • options : Same object as in the connect official API.

  • ComponentClass : Component class to connect with state and actions.

Examples

Simple state

import autoConnect from 'react-redux-simple-autoconnect';
import TodoComponent from './Todo';
import actions from './actions';

const Todo = autoConnect((state) => [state], () => [actions])(TodoComponent);

export default Todo;

Multiple state (substate)

import autoConnect from 'react-redux-simple-autoconnect';
import TodoComponent from './Todo';
import actions from './actions';
import actions2 from './actions2';

const Todo = autoConnect((state) => [state.generalState, state.subState1], () => [actions, action2])(TodoComponent);

export default Todo;

Thanks

  • My wife BH to support me doing this

Author

  • Oxyno-zeta (Havrileck Alexandre)

Readme

Keywords

none

Package Sidebar

Install

npm i react-redux-simple-autoconnect

Weekly Downloads

4

Version

1.0.0

License

Apache-2.0

Last publish

Collaborators

  • oxyno-zeta