标签:vertica 接收 渲染 lan horizon 移除 结果 tar ica
这是React不能识别dom元素上的非标准attribute报出的警告,最终的渲染结果中React会移除这些非标准的attribute。
通常{...this.props}和cloneElement(element, this.props)这两种写法,会将父级别无用的attribute传递到子级的dom元素上。
例如:
function MyDiv(props) { if (props.layout === ‘horizontal‘) { // BAD! Because you know for sure "layout" is not a prop that <div> understands. return <div {...props} style={getHorizontalStyle()} /> } else { // BAD! Because you know for sure "layout" is not a prop that <div> understands. return <div {...props} style={getVerticalStyle()} /> } }
可以使用rest参数接收,删除等方法来解决:
const { layout, ...rest } = props //或者 const divProps = Object.assign({}, props); delete divProps.layout;
具体可参考:React官方文档 Unknown Prop Warning
warning: React does not recognize the xxx prop on a DOM element
标签:vertica 接收 渲染 lan horizon 移除 结果 tar ica
原文地址:https://www.cnblogs.com/mengff/p/9822266.html