Javascript React-将值传递给setState回调
我试图将在prevState回调之外确定的值传递到函数中。以下是我所拥有的:Javascript React-将值传递给setState回调,javascript,reactjs,Javascript,Reactjs,我试图将在prevState回调之外确定的值传递到函数中。以下是我所拥有的: uncheckAllUnsentHandler = (e) => { const newCheckMarkValue = e.target.checked; this.setState((prevState, props, newCheckMarkValue) => { const newUnsentMail = prevState.unsentMail.map(policy =
uncheckAllUnsentHandler = (e) => {
const newCheckMarkValue = e.target.checked;
this.setState((prevState, props, newCheckMarkValue) => {
const newUnsentMail = prevState.unsentMail.map(policy => {
mail.willSend = newCheckMarkValue;
return mail;
});
return {
unsentMail: newUnsentMail
}
});
}
newCheckMarkValue在map函数中未定义,我不知道为什么
详细说明:
我有一个表,客户可以在其中选择是否发送邮件。默认情况下,表中的所有邮件项目都被选中。在标题中,他们可以取消选中/全部选中。我试图调整表中邮件项目的状态,以便在单击标题复选框取消选中时取消选中(willSend是邮件中邮件项目的属性)。如果我在下面的代码中将willSend硬编码为true或false(例如:mail.willSend=true;),那么所有这些都会起作用,但我似乎无法在中获取标题中复选框的值。
updater函数只接受两个参数,state
和props
<代码>状态是对应用更改时组件状态的引用
(state, props) => stateChange
您只需访问unchecklunsenthandler
外部范围中包含的newCheckMarkValue
版本
uncheckAllUnsentHandler = (e) => {
const newCheckMarkValue = e.target.checked;
this.setState((prevState, props) => {
const newUnsentMail = prevState.unsentMail.map(policy => {
mail.willSend = newCheckMarkValue;
return mail;
});
return {
unsentMail: newUnsentMail
}
});
}