Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 带有React的未知属性,如何创建新的html属性_Javascript_Reactjs_React Proptypes - Fatal编程技术网

Javascript 带有React的未知属性,如何创建新的html属性

Javascript 带有React的未知属性,如何创建新的html属性,javascript,reactjs,react-proptypes,Javascript,Reactjs,React Proptypes,我正在尝试为我的收音机和复选框的输入元素创建一个:不确定的属性 react引发了以下错误: Unknown prop `indeterminate` on <input> tag. Remove this prop from the element 标签上的未知属性“不确定”。从元件上拆下此支柱 是否可以创建新的道具或道具是否完全锁定?只需将输入包装到另一个可以接受不确定的道具的组件中: const IndeterminateInput = React.createClass({

我正在尝试为我的收音机和复选框的输入元素创建一个
:不确定的
属性

react引发了以下错误:

Unknown prop `indeterminate` on <input> tag. Remove this prop from the element
标签上的未知属性“不确定”。从元件上拆下此支柱

是否可以创建新的道具或道具是否完全锁定?

只需将输入包装到另一个可以接受不确定的
道具的组件中:

const IndeterminateInput = React.createClass({
  render() {
    // Create props clone
    const cleanProps = Object.assign({}, this.props);
    delete cleanProps['indeterminate'];
    return <input ref="input" {...cleanProps}/>
  },
  updateInput: function () {
    this.refs.input.indeterminate = Boolean(this.props.indeterminate);
  },
  componentDidMount() {
    // Initial render
    this.updateInput();
  },
  componentDidUpdate() {
    // Props change
    this.updateInput();    
  } 
});
<IndeterminateInput type="checkbox" indeterminate />
<!-- This does not work! -->
<input type="checkbox" indeterminate>