An open API service indexing awesome lists of open source software.

https://github.com/cncolder/react-dom-attrs

A filter pick react known dom attrs from props
https://github.com/cncolder/react-dom-attrs

react react-attrs react-dom react-dom-attrs react-props react-toolbox

Last synced: about 1 month ago
JSON representation

A filter pick react known dom attrs from props

Awesome Lists containing this project

README

          

# React DOM Attrs

A filter pick react known dom attrs from props. Help you avoid [React Unknown Prop Warning](https://facebook.github.io/react/warnings/unknown-prop.html)

```
npm install --save react-dom-attrs
```

OR

```
yarn add react-dom-attrs
```

[![npm](https://img.shields.io/npm/v/react-dom-attrs.svg)](https://www.npmjs.com/package/react-dom-attrs)
![module formats: cjs](https://img.shields.io/badge/module%20formats-cjs-green.svg)

## Example

### API

```js
/**
* @param {{}} props - React component props
* @return {{}} - DOM safe attrs
*/
domAttrs(props: {}): {}
```

```js
const domAttrs = require('react-dom-attrs')

domAttrs({ width: 10, height: 10 }) // { width: 10, height: 10 }

domAttrs({ onClick: () => { } }) // { onClick: [Function: onClick] }

domAttrs({ bad: 10 }) // { }
```

### Full react example

```jsx
const domAttrs = require('react-dom-attrs')

const Card = props => {
const { className, firstName, lastName, ...rest } = props

// 'lol' in rest
const attrs = domAttrs(rest)
// 'lol' removed but width and height leave there

return (


Full Name: {firstName} {lastName}

)
}

const App = () => (

)
```

## Limits

This module only pick DOM safe attrs and donot care what element you will pass to.

e.g.

```jsx
var Div =


```

You will got

```html


```
## Acknowledgements

The attr list used by this project come from [styled-components](https://github.com/styled-components/styled-components). We'd like to thank styled components team ideas, code or inspiration.