const dom = new DOMParser().parseFromString(<user input>);
const node = e => React.createElement(
e.localName,
[...e.attributes]
.map(attr => attr.name)
.reduce((props, name) => {
//i need that test
if (<name is a proper react attribute>) {
props[name] = e.getAttribute(name);
}
return props;
}, {}),
[...e.children].map(child => node(child))
);
React正在抱怨
Unknown props
xlink:href
如果输入为svg。所以我需要过滤掉所有未知的道具。为了做到这一点,将该列表作为JS对象将非常有用。
我想知道的是:
import { KnownProps } from 'react';
const testIfProperName = name =>
KnownProps.hasOwnProperty(name);
编写所需的测试。