react-merge-props
TypeScript icon, indicating that this package has built-in type declarations

0.1.4 • Public • Published

react-merge-props

NPM version Build Status Test Coverage Dependency Status DevDependency Status License PR Welcome

Deep props merging functionality for React.

Introduction

Merging react component props by the following rule:

  1. Normal props replace the former
  2. children are ignored
  3. className are concatenated
  4. style are shallow merged
  5. functions that have initial on are run in sequence from left to right

When creating extensible react components, this is what we need.

The first argument is mutated for performance reason. If you don't want this behavior, please pass the first argument as an empty object.

Installation

Install this package with npm.

npm i react-merge-props -s

Usage Pattern

This package is very useful when creating wrapping components. For example:

import React from 'react';
import mergeProps from 'react-merge-props';
 
const HeadingOne = (props) => (
  <h1 {...mergeProps({ style: { 'color': 'red' }}, props)}>{props.children}</h1>
);
 
export default HeadingOne;

License

MIT © Zhang Kai Yu

Readme

Keywords

none

Package Sidebar

Install

npm i react-merge-props

Weekly Downloads

91

Version

0.1.4

License

MIT

Unpacked Size

6.62 kB

Total Files

5

Last publish

Collaborators

  • cheunghy