我想在 Change 上发布 switch bool 值时遇到错误。我正在使用 React/Typescript...我想在这里执行的操作是在handleChange() 函数中发送 bool 值的发布请求,我该怎么做?
我收到的当前错误是 Type 'void' is not assignable to type '((event: ChangeEvent<HTMLInputElement>, checked: boolean) => void) | undefined'
interface IState {
application?: Map<{}, {}>;
hasChanged?: boolean;
checkedA?: boolean;
}
<div className={classes.switchContainer}>
<FormGroup row>
<FormControlLabel
control={
<Switch
checked={this.state.checkedA}
onChange={this.handleChange()}
value="checkedA"
>Toggle</Switch>
}label="YES"
/>
<Typography color="secondary" variant="body1" className={classes.toggleQuestions}>Is the Mentor information complete?</Typography>
</FormGroup>
</div>
@autobind
private handleChange() {
console.log("checkedA")
}
最佳答案
尝试使用 onChange={this.handleChange} 按照您的方式,您调用处理更改并将其返回值(“void”)设置为更改处理程序。在某些情况下这可能是合适的,但不适合您的情况。
关于javascript - Void 类型不可分配给 Boolean 类型(React/Typescript),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54166055/