![](/img/trans.png)
[英]Reference Material UI SelectField component from onChange handler
[英]onChange In SelectField Component For Material-UI / React is not accepting onChange from parent Component
因此,我的工作场所在组件中使用SelectField,该组件在多个地方使用。 说得通。 现在,当我在当前组件中使用该组件时。 我创建的onChange事件未传递正确完成所需的值。 现在,如果我将SelectField更改为onChange = {onChange},则可以正常工作。 但是,无法以这种方式设置它,因为它在应用程序内的其他部分都依赖于它。 我是React的新手。 这是我的功能
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,
});
}
这是我要导入并与组件一起使用的CompanySelectField
<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本身
<SelectField
name={name}
maxHeight={300}
value={value}
onChange={(event, index, response) => onChange(response)}
disabled={disabled}
hintText={hint}
>
提前谢谢你。
您从addHistory返回的方法有4个参数,即event, index, value, target
而您从SelectField组件调用的方法即onChange={(event, index, response) => onChange(response)}
只有一个参数,并且响应也与上述返回方法的第一个参数不匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.