# babel-plugin-jsx-merge-props

> Plugin that merge props of JSX with babel

Latest version **0.0.2** (published 2019-07-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-jsx-merge-props
pnpm add babel-plugin-jsx-merge-props
yarn add babel-plugin-jsx-merge-props
bun add babel-plugin-jsx-merge-props
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2019-07-30 |
| First published | 2019-07-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 4.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | hooriza@gmail.com |
| Maintainers | hooriza |
| Keywords | babel-plugin, jsx, merge-props |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-jsx-merge-props
- Repository: https://github.com/hooriza/babel-plugin-jsx-merge-props
- Issues: https://github.com/hooriza/babel-plugin-jsx-merge-props/issues
- npm.io page: https://npm.io/package/babel-plugin-jsx-merge-props

## Dependencies (5)

- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.5.5
- [@babel/plugin-syntax-jsx](https://npm.io/package/@babel/plugin-syntax-jsx.md) ^7.2.0
- [@babel/helper-plugin-utils](https://npm.io/package/@babel/helper-plugin-utils.md) ^7.0.0
- [@babel/helper-builder-react-jsx](https://npm.io/package/@babel/helper-builder-react-jsx.md) ^7.3.0
- [@babel/plugin-transform-runtime](https://npm.io/package/@babel/plugin-transform-runtime.md) ^7.4.3

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.0.2 (latest) — 2019-07-30

## README

# babel-plugin-jsx-merge-props

[![Build Status](https://travis-ci.org/hooriza/babel-plugin-jsx-merge-props.svg?branch=master)](https://travis-ci.org/hooriza/babel-plugin-jsx-merge-props)
[![npm](https://img.shields.io/npm/v/babel-plugin-jsx-merge-props.svg)](https://www.npmjs.com/package/babel-plugin-jsx-merge-props)
![size](https://img.shields.io/bundlephobia/minzip/babel-plugin-jsx-merge-props.svg)


## Why?
It's annoying to use props that provided from multiple [hooks](https://reactjs.org/docs/hooks-intro.html).

```jsx
const useFirstHook = () => {
  ...

  return {
    className,
    style,
    onClick,
  };
};

const useSecondHook = () => {
  ...

  return {
    value,
    style,
    onClick,
  };
};
```

```jsx
const MyComponent = () => {
  const first = useFirstHook(...);
  const second = useSecondHook(...);

  const handleClick = useCallback(event => {
    first.onClick(event);
    second.onClick(event);
  }, [first, second]);

  return (
    <input
      type="text"
      {...first}
      {...second}
      className={[first.className, second.className].join(' ')}
      style={{ ...first.style, ...second.style }}
      onClick={handleClick}
    />
  );
}
```

Or would be better to use some package like [`merge-props`](https://github.com/andrewbranch/merge-props),
but It's still little bit bothersome.

```jsx
import mergeProps from 'merge-props';

const MyComponent = () => {
  const first = useFirstHook(...);
  const second = useSecondHook(...);

  return (
    <input
      type="text"
      {...mergeProps(first, second)}
    />
  );
}
```

You can just write like below with this plugin.

```jsx
import mergeProps from 'merge-props';

const MyComponent = () => {
  const first = useFirstHook(...);
  const second = useSecondHook(...);

  return (
    <input merge={mergeProps}
      type="text"
      {...first}
      {...second}
    />
  );
}
```

## Installation
```
npm install --save-dev babel-plugin-jsx-merge-props
```

## Usage
`.babelrc`:
```json
{
  "plugins": [ "babel-plugin-jsx-merge-props" ]
}
```

---
_Source: https://npm.io/package/babel-plugin-jsx-merge-props · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
