react-dom-props
We cannot set {...props} to DOM Element directly as there might be some non-supported props. And it would be tedious to map them one by one.
In case of single DOM Element we would like to manipulate inside a component, react-dom-props
provides what you need. It will simply pick supported DOM props as listed in https://reactjs.org/docs/dom-elements.html
Install
yarn add react-dom-props
Usage
// simply import from package if you need both of themimport pickHtmlProps pickSvgProps from 'react-dom-props'; // if you just need one of them, import the member explictly like below to reduce bundle sizeimport pickHtmlProps from 'react-dom-props/dist/pickHtmlProps';import pickSvgProps from 'react-dom-props/dist/pickSvgProps'; const MyComponent = { // some logic here // pick html or svg props supported by React const htmlProps = ; const svgProps = ; // then pass htmlProps or svgProps to the DOM element you would like to manipulate return // html tag <div /> // OR svg tag <svg /> ;};