npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-redux-connect-helpers

v3.0.3

Published

Helpful set of functions for connecting redux state to react components.

Downloads

27

Readme

React Redux Connect Helpers

A helpful set of functions for connecting redux state to react components.
Compose your connectors at will and build the connected component of your dreams... 😴

Build Status Dependency Status devDependency Status JavaScript Style Guide

Installation

$ npm install react-redux-connect-helpers

Usage

import React from 'react'
import { compose } from 'react-redux'
import {
  connectValue,
  connectStateValue,
  createActionConnector
} from 'react-redux-connect-helpers'

// 1. Given a component we wish to connect to state
const ButtonWithText = props =>
  <button
    className={props.active ? 'active' : ''}
    onClick={props.onClick}
  >
    {props.text}
  </button>

// 2. And action creators to be bound to dispatch (optional)
const actionCreators = {
  toggleMenuActiveState: () => ({
    type: 'TOGGLE_MENU_ACTIVE_STATE',
    payload: null
  })
}

// 3. We can connect property 'text' as value 'Menu'
const textProp = connectValue('Menu', 'text')

// 4. We can connect property 'active' as value at state.menu.active
const activeProp = connectStateValue(['menu', 'active'], 'active')

// 5. We can create an action connecting helper for our actionCreators
const connectAction = createActionConnector(actionCreators)

// 6. And then connect property 'onClick' as a bound action creator toggleMenuActiveState
const onClickProp = connectAction('toggleMenuActiveState', 'onClick')

// 7. Finally, we can connect our component with all the desired props
const ToggleMenuButton = compose(
  textProp
  activeProp,
  onClickProp
)(ButtonWithText)

export default ToggleMenuButton

Immutable

If your redux store uses Immutable.js, import with react-redux-connect-helpers/immutable

API Reference

connectStateValue

Returns a function that connects a value in state to a React component as a prop

Parameters

Examples

const BandContainer = compose(
  connectStateValue('name'),
  connectStateValue(['musicians'], 'members'),
  connectStateValue(
    ['discography', 'albumsByYear'],
    'firstThreeAlbums',
    (albumsByYear, state) => albumsByYear.slice(0, 3)
  )
)(BandComponent)

Returns function Connected component class

connectValue

Returns a function that connects a value to a React component as a prop

Parameters

Examples

const TitleContainer = compose(
  connectValue('purple', 'color'),
  connectValue('You\'re Living All Over Me', 'title')
)(TitleComponent)

Returns function Connected component class

createActionConnector

A higher order function that returns a function to connect bound actions to React components as props

Parameters

Examples

const actionCreators = { purchaseAlbum, ... }
const connectAction = createActionConnector(actionCreators)
const PurchaseButton = compose(
  connectAction('purchaseAlbum', 'onClick')
)(ButtonComponent)

Returns function Helper to connect an action