1
"コード編成"を除いて、これらの2つの方法に違いはありますか?レンダリング機能のHOC対ラッパー
私は私が直接
const TextInput = (props) => <input type="text" {...props} />
const App = (mainProps) => <div>
<TextInput {...props} errors={['error text']} />
</div>
それらを使用して、私はすべての入力コンポーネントのレンダリングエラーメッセージをカプセル化するコンポーネントをFormInputしているなどのTextInput、NumberInput、などの
、カスタム入力elemtsの束を持っています。あなたのケースでは
const FormInput = (props) => <div>
// Render input here
<span>{props.errors.join(', ')}</span>
</div>
私は2つの異なる実装 1を参照)HOC
const FormInputHOC = (C) => {
const FormInput = (props) => <div>
<C {...props} />
<span>{props.errors.join(', ')}</span>
</div>
}
export default FormInputHOC(TextInput)
2)ラッパー
const FormInput = (props) => <div>
{props.children}
<span>{props.errors.join(', ')}</span>
</div>
const TextInput = (props) => <FormInput errors={props.errors}>
<input type="text" {...props} />
</FormInput>