私の職場では、複数の場所で使用されているコンポーネントの中でSelectFieldを使用しています。意味をなさない今、私が作業している現在のコンポーネントの中でそのコンポーネントを使用するとき。私が作成したonChangeイベントは、正しく完了するために必要な値を渡しません。今度は、SelectFieldをonChange = {onChange}に変更するとうまく動作します。しかし、アプリ内の他の部分が依存しているので、このように設定することはできません。私はReactを初めて使う人です。ここで私は、インポートおよびコンポーネントここonChange In SelectableField Component for Material-UI/Reactが親からonChangeを受け入れていないコンポーネント
<CompanySelectField
label={translations.translate('driverProperties', 'typeOfVehicle')}
hint={translations.translate('driverProfile', 'pleaseSelectRole')}
style={{ marginTop: '25px' }}
name={'roles'}
value={this.state.history.roles}
onChange={this.addHistory('roles')}
fullWidth
required
>
を使用していますCompanySelectFieldここに私の機能
addHistory = (field) => (event, index, value, target) => {
const { history } = this.state;
console.log(this.state.history);
console.log(field);
if (field === 'employerName' || field === 'description') {
history[field] = event.target.value;
} else if (field === 'roles') {
history[field] = value;
} else {
history[field] = event.value;
}
this.setState({
history: this.state.history,
});
}
されている
<SelectField
name={name}
maxHeight={300}
value={value}
onChange={(event, index, response) => onChange(response)}
disabled={disabled}
hintText={hint}
>
は前もってありがとうCompanySelectFieldそのものです。
あなたが正しくあなたを理解していれば、SelectFieldのonChange小道具を変更すると問題は解決します。=>(イベント、インデックス、レスポンス)=> onChange(イベント、インデックス、レスポンス)} –
パーフェクト、ありがとう –