2017-02-21 10 views
1

ラジオとチェックボックスの入力要素に:indeterminateプロパティを作成しようとしています。不明ReactのProp、新しいhtmlプロパティの作成方法

は私がによってスローされた次のエラーが反応しています

Unknown prop `indeterminate` on <input> tag. Remove this prop from the element 

それは新しい小道具を作成することは可能ですか、それは完全にロックされていますか?

答えて

1

単にindeterminate小道具を受け入れることができます別のコンポーネントへの入力をラップ:そして、あなたがラッパーとしてこのコンポーネントを使用することができます

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();  
    } 
}); 

:でもHTML indeterminateになっていないことを

<IndeterminateInput type="checkbox" indeterminate /> 

お知らせ有効な属性DOMを手動で更新する必要があります。

<!-- This does not work! --> 
<input type="checkbox" indeterminate> 
関連する問題