# filter-react-props

> Filter React & DOM props.

Latest version **0.0.4** (published 2017-11-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install filter-react-props
pnpm add filter-react-props
yarn add filter-react-props
bun add filter-react-props
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2017-11-30 |
| First published | 2017-11-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Maciej Leszczyński |
| Maintainers | asistapl |
| Keywords | react, preact, props |

## Links

- npm: https://www.npmjs.com/package/filter-react-props
- Repository: https://github.com/asistapl/filter-react-props
- Homepage: https://github.com/asistapl/filter-react-props#readme
- Issues: https://github.com/asistapl/filter-react-props/issues
- npm.io page: https://npm.io/package/filter-react-props

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.0.4 (latest) — 2017-11-30
- 0.0.3 — 2017-11-04
- 0.0.2 — 2017-11-04
- 0.0.1 — 2017-11-04

## README

<h1 align="center">
  ⚛️✔️ filter-react-props
  <br>
  <br>
</h1>

Filter allowed React & DOM props to avoid warnings and unnecessary attributes in HTML output.

It's only 1.3 kB *(gziped UMD version, it's even less when you uglify ES Modules verision)*.

## Installation

yarn
```
yarn add filter-react-props
```

npm
```
npm install --save filter-react-props
```

cdn
```
https://unpkg.com/filter-react-props
```

## Usage

```jsx
import filterReactProps from 'filter-react-props'

or

const filterReactProps = require('filter-react-props')

or

<script src="https://unpkg.com/filter-react-props"></script>
const { default: filterProps } = filterReactProps
```

## Use case

Consider this style component:

```jsx
const Button = props => (
  <button
    style={{ color: props.color }}
    {...props}
  />
)

<Button color="green">My Button</Button>
```

Button will render with unnecessary `color` attribute.

```html
<button color="green" style="color: green;">My Button</button>
```

It can be avoided by destructuring props object:
```jsx
const Button = ({ color, ...props }) => (
  <button
    style={{ color }}
    {...props} // Props without color
  />
)
```

But you can't apply this solution when you don't know what props will be passed. This is use case for this package:

```jsx
import filterReactProps from 'filter-react-props'

const Button = props => (
  <button
    style={getStylesFromProps(props)}
    {...filterReactProps(props)}
  />
)

<Button fontSize={24} color="green">My Button</Button>
```

## Full API

```js
import
// Get new object with allowd React & DOM props.
filterReactProps,
{
  // Array of allowed React & DOM props.
  // List borrowed from `react-emotion` package.
  allowedProps,

  // Regular expression for checkig if given string
  // is allowed React or DOM prop.
  // Necessary for checking data-* and aria-* attributes.
  allowedPropsRegExp,

  // Check if given prop is allowed React or DOM prop.
  isPropAllowed
} from 'filter-react-props'
```

## Package versions

Package comes in three versions:
- UMD - transpiled, bundled, minified (`main` field in `package.json`) - for use in browser or CommonJS.
- ES Modules - transpiled ES Modules (`module` field in `package.json`) - for tree shaking.
- ES Next - untranspiled ES Modules (`exnext` field in `package.json`) - [read why](http://2ality.com/2017/06/pkg-esnext.html).

## Used in

[📐 spaced-components](https://github.com/asistapl/spaced-components)

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