Skip to content

tophat/with-immutable-props-to-js

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

with-immutable-props-to-js

Logo

npm CICD npm downloads codecov Renovate enabled All Contributors Discord Maturity badge - level 3

A higher-order component for keeping Immutable objects outside your presentational components

Installation

yarn add with-immutable-props-to-js

or

npm install with-immutable-props-to-js

This library also lists react, react-dom, and immutable as peer dependencies, so make sure they are installed in your project as well.

Usage

import withImmutablePropsToJS from 'with-immutable-props-to-js'

If you're not using ECMAScript modules:

const withImmutablePropsToJS = require('with-immutable-props-to-js').default

Example:

import React from 'react'
import { connect } from 'react-redux'
import withImmutablePropsToJS from 'with-immutable-props-to-js'

const MyDumbComponent = props => {
   // ...
   // props.objectProp is turned into a plain JavaScript object
   // props.arrayProp is turn into a plain JavaScript array
}

MyDumbComponent.propTypes = {
   objectProp: PropTypes.object,
   arrayProp: PropTypes.array,
}

const mapStateToProps = state => ({
   objectProp: mySelectorThatReturnsImmutableMap(state),
   arrayProp: mySelectorThatReturnsImmutableList(state),
})

export default connect(mapStateToProps)(withImmutablePropsToJS(MyDumbComponent))

Motivation

You can read about the rationale for this higher-order component here.

Contributors

For information on how to contribute to this project, check out the contributing guide.

Thanks goes to these wonderful people (emoji key):


Michael Rose

πŸ’» πŸ“– πŸš‡

Brandon Baksh

πŸš‡

greenkeeper[bot]

πŸš‡

Jake Bolam

πŸ“– πŸš‡

Sanchit Gera

πŸ“–

Siavash Mahmoudian

πŸš‡

monicamm95

🎨

Danilo Matamoros

πŸ’»

Roman Mahotskyi

πŸš‡

Pablo Morra

πŸ’» ⚠️

dependabot[bot]

πŸš‡

jinwoo choi

πŸ’»

Marc Cataford

πŸ“–

Michael Chen

πŸ’»

This project follows the all-contributors specification. Contributions of any kind welcome!

Credits

Special thanks to Carol Skelly for donating the 'tophat' GitHub organization.