このライブラリの問題を修正したいと思います:react-form。詳細について 、これは私の現在のエラーです:ネストされたコンポーネントreact.cloneElement with react-form
Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. Check the render method of
CustomInput
.
これは私がやろうとしているものです:
<CustomInput field="date" showErrors={false}>
<DatePickerForm />
</CustomInput>
これは私のCustomInputコンポーネントです:
import React, { Component } from 'react';
import FormInput from 'react-form';
class CustomInput extends Component {
render() {
const { showErrors, field, children } = this.props;
return (
<FormInput showErrors={showErrors} field={field}>
{({ setValue }) => {
return (
React.cloneElement(children, { setValueForm: setValue })
);
}}
</FormInput>
);
}
}
export default CustomInput;
React.cloneElement(children、{setValueForm:setValue})はオブジェクトを返すようです。 しかし、 "FormInput"部分のないReact.cloneElementをレンダリングすれば、レンダリングは正常です。 FormInputの機能に問題があると思います。
どうすれば間違っていますか?
あなたはFormInput class
感謝を確認することができます。あなたは間違って読み込むよう
とは対照的にhttps://www.npmjs.com/package/react-form#-forminput-
をあなたは正確にあなたがそこに達成しようとしているのかを説明することはできますか? – Dekel
@Dekel書くことで説明するのはとても複雑です^^。私の最終的なポイントは:私は(フォームを使用する)各コンポーネントを書くことを望まない、 " blablabla " ...私はちょうど方法が好きです。最初にもっと読みやすい。 第2に、FormInputの各子コンポーネント(この例ではdatepicker)では、現在のフォームの各フィールドにデフォルト値を設定する必要があります。だから、毎回、これを書いて、私はより読みやすいビッグフォームのコンポーネントを持っているようにしています。 –