高次コンポーネント内のコンポーネントからPropTypeを作成した場所を指す方法がありますか?高次コンポーネントのPropTypes
これは小さなサンプルですが、別々のファイルで、アプリケーション全体EnhancedButtons
複数あった場合、これは、デバッグには非常に難しいだろう。
高位コンポーネントは理想的には再利用性のために作られているため、handleClickメソッドが見つからないコンポーネントの場所を知ることはできません。 _EnhancedButton
のレンダリングメソッドは、拡張する必要があるComponent
の変数です。
FinalButton
が挿入されていて、_EnhancedButton
のインスタンスであり、prop handleClickClickが欠けているなど、PropTypesを作成している場所をより明白にする方法はありますか?あなたの例では
https://jsfiddle.net/kriscoulson/sh2b8vys/3/
var Button = (props) => (
\t <button onClick={() => props.handleClick() }>
\t \t Submit
\t </button>
);
Button.propTypes = {
\t handleClick: React.PropTypes.func.isRequired
}
const EnhanceButton = Component => class _EnhancedButton extends React.Component {
\t render() {
\t return (<Component { ...this.props }>{this.props.children}</Component>);
}
}
const FinalButton = EnhanceButton(Button);
ReactDOM.render(
<FinalButton />,
document.getElementById('container')
);
<script src="https://facebook.github.io/react/js/jsfiddle-integration-babel.js"></script>
<div id="container">
<!-- This element's contents will be replaced with your component. -->
</div>
ありがとうございます! :) – Mihir