https://github.com/nehle/dom-props-react
https://github.com/nehle/dom-props-react
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/nehle/dom-props-react
- Owner: Nehle
- License: mit
- Created: 2017-08-08T11:44:57.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-08-08T14:33:38.000Z (almost 9 years ago)
- Last Synced: 2025-10-08T17:34:04.479Z (8 months ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dom-props-react
A simple library listing all dom properties React accepts, as well as basic validator functions for them.
## Usage
### filterDomProps
`var filterDomProps = require("dom-props-react").filterDomProps`
This function takes a props object and filter out all non-dom props for you to pass on to dom elements. It takes and optional `filterOpts` object that can turn on or off `html`, `aria`, `data` and `svg` property filtering. By default all are enabled
Example:
```js
var myProps = {
invalidProp: "value",
"aria-hidden": true,
"data-x": "x",
fontFamily: "Arial",
className: "myClass"
}
var filtered = filterDomProps(myProps); //{"aria-hidden": true, "data-x": "x", fontFamily: "Arial", className: "myClass"}
var filteredAria = filterDomProps(myProps, {html: false, svg: false, data: false}) //{"aria-hidden": true}
```
### isValidAttribute
If you don't want to import all the dom properties (it's basically just three long arrays with all props), you can choose to import just the one you want by doing `require` on `dom-props-react/html`, `dom-props-react/svg`, `dom-props-react/aria` or `dom-props-react/data`. All of these export a function called `isValidAttribute()` that simply takes a string name and returns whether it's valid for that domain. Additionally, all but `dom-props-react/data` export an `attributes` array that simply lists all valid attributes for their domain