我正在尝试发布开关输入切换控件的状态值,但是当我使用按钮发送发布请求功能submitRecommendation()
时,出现了JSON parse error: Cannot deserialize instance of `boolean` out of START_OBJECT token; nested exception
错误。
我在这里做错了什么?有没有一种方法可以编写此函数以具有多个切换控件,而无需重复代码?
interface IState {
mentorInfoComplete?: boolean;
hasChanged?: boolean;
}
class Component extends React.Component<Props, State> {
public state: State = {
mentorInfoComplete: false
}
public render() {
const {} = this.props;
const { mentorInfoComplete } = this.state;
const {} = this;
<div className={classes.switchContainer}>
<FormGroup row>
<FormControlLabel
control={
<Switch
checked={mentorInfoComplete}
onChange={this.handleChange}
value={mentorInfoComplete}
>Toggle</Switch>
}label="YES"
/>
<Typography color="secondary" variant="body1" className={classes.toggleQuestions}>Is this question complete</Typography>
</FormGroup>
</div>
<Button
color="primary"
className="reviewApplication-back"
variant="contained"
type="submit"
onClick={this.submitRecommendation}>
Recommend Approval
</Button>
private handleChange() {
this.setState({
mentorInfoComplete: true
});
console.log(this.state);
}
private async submitRecommendation() {
const {
application,
mentorInfoComplete
} = this.state;
if (!application) {
return;
}
try {
await axios.post(
`/mentorApplication/${match.params.applicationId}/checklist`,
{
mentorInfoComplete: { mentorInfoComplete }
}
);
}
}
最佳答案
不知道API,我的猜测是这是令人反感的行:mentorInfoComplete: { mentorInfoComplete }
您本质上就是做到了mentorInfoComplete: { true }
当我猜你想要什么mentorInfoComplete: true
尝试摆脱多余的括号,看看是否有帮助?