react-redux-clean-connect
TypeScript icon, indicating that this package has built-in type declarations

1.0.9 • Public • Published

react-redux-clean-connect NPM version Build Status Dependency Status Coverage percentage

A React Redux helper for less React connect boilerplate

Installation

$ npm install --save react-redux-clean-connect

Usage

// Connecting can look like this: ▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼

import * as React from 'react'
import { cleanConnect } from 'react-redux-clean-connect'
import { getByUUID, updateSearchCriteria } from '../state/actions/userActions'

const mapStateAndDispatchToProps = (propsFromState, ownProps) => {
  const partialState = propsFromState.partialState

  return {
    // state props
    errorMessage: partialState.error.message,
    username: partialState.searchCriteria.username,
    usersObj: partialState.usersObj,

    // dispatch props
    getByUUID: () => getByUUID(partialState.searchCriteria),
    updateSearchCriteria,
  }
}

export default cleanConnect(mapStateAndDispatchToProps)(
    class UserList extends React.Component {


// Instead of looking like this: ▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼

import * as React from 'react'
import { connect } from 'react-redux'
import { getByUUID, updateSearchCriteria } from '../state/actions/userActions'

const mapStateToProps = (store, ownProps) => {
  return {
    ...ownProps,
    errorMessage: partialState.error.message,
    username: partialState.searchCriteria.username,
    usersObj: partialState.usersObj,
  }
}

const mapDispatchToProps = {
  getByUUID,
  updateSearchCriteria
}

const mergeProps = (propsFromState, propsFromDispatch, ownProps) => {
  const partialState = propsFromState.partialState

  return {
    ...ownProps,
    ...propsFromState
    ...propsFromDispatch
    getByUUID: () => propsFromDispatch.getByUUID(partialState.searchCriteria),
  }
}

export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(
  class Loyalty extends React.Component<any, any> {

License

MIT © PC Thomatos

Dependencies (0)

    Dev Dependencies (21)

    Package Sidebar

    Install

    npm i react-redux-clean-connect

    Weekly Downloads

    0

    Version

    1.0.9

    License

    MIT

    Unpacked Size

    9.37 kB

    Total Files

    6

    Last publish

    Collaborators

    • pcthomatos