私は入力とツールチップをレンダリングし、状態を制御するクラスコンポーネントを持っています。 <SelectInputType>
コンポーネントジョブは、 'タイプ'の単一の小道具を取り、テキスト入力、テキストエリア、選択入力、またはチェックボックスグループコンポーネントのいずれかをレンダリングすることです。このSelectInputTypeコンポーネントを通過する必要のある小道具があり、その中には入力コンポーネントの4つすべてに関連するもの(placeholderTextとたとえば必要)と、特定の入力に固有のものがあります(オプションは次のとおりです)。チェックボックスや選択入力にのみ関連します)。マイSelectInputTypeコンポーネントは次のようになります変数を介してコンポーネントに小道具を渡す
render() {
const inputProps = {};
inputProps.placeholderText = this.props.placeholderText;
inputProps.required = this.props.required;
inputProps.class = this.props.class;
inputProps.value = this.props.value;
inputProps.options = this.props.options;
inputProps.updateText = this.handleInput;
inputProps.handleFocus = this.focusIn;
inputProps.handleBlur = this.focusOut;
inputProps.handleCheckboxChange = e => this.addCheckboxToList(e);
inputProps.closeCheckboxSelector = this.closeCheckboxSelector;
inputProps.readableSelectedCheckboxes = this.state.readableSelectedCheckboxes;
const inputClass = classNames('input-with-tooltip', {
focus: this.state.focus,
'step-complete': this.state.completed,
});
return (
<div className={inputClass}>
<InputTooltip
tooltipText={this.props.tooltipText}
completed={this.state.completed}
/>
<div className="drill-creation-input">
<SelectInputType type={this.props.type} {...inputProps} />
</div>
</div>
);
}
...
const SelectInputType = (props) => {
let component;
if (props.type === 'title') {
component = <TextInput />;
} else if (props.type === 'text') {
component = <TextareaInput />;
} else if (props.type === 'checkbox') {
component = <CheckboxInput />;
} else if (props.type === 'select') {
component = <SelectInput />;
}
return (
<div>
{component}
// Need to pass props through to this?
</div>
);
};
私はSelectInputTypeコンポーネントまで小道具を渡すためにJSXの広がりを属性使用していますが、私はそれから渡す方法がわかりませんこれらは4つの入力コンポーネントに適用されます(特定のコンポーネントで有効でない特定のプロップではエラーが発生します)
を私はこれを行う場合、私はこのエラーを取得する:警告:React.createElement:タイプが無効です - 予想文字列(内蔵用(コンポーネントの場合)またはクラス/関数(コンポジットコンポーネントの場合)ですが、未定義です。 – GuerillaRadio
'TextInput'、' TextareaInput'、 'CheckboxInput'、そして' SelectInput'はすべて値を持っていますか?どんなタイプミス? – tenor528
あなたの 'if'ステートメントの1つは間違いなくキャッチしていますか? 'props.type'が 'title'、 'text'、 'checkbox'、 'select'と等しくない場合はどうでしょうか? – tenor528