function handleTOSChecked(e) {
setTosChecked(!tosChecked);
// updates inside functions are batched and flushed out on next render cycle
if (tosChecked && privacyChecked) {
setCanSubmit(true);
} else {
setCanSubmit(false);
}
// the values of tosChecked and privacyChecked dont change
// similar thing must be happing even if this code is inside a function called from this code
console.log(tosChecked, privacyChecked);
}
1条答案
按热度按时间v09wglhw1#
直接设置计算属性,避免冗余状态
代码未按预期工作的可能原因是批量更新或需要反转禁用属性
disabled={!canSubmit}
希望能有所帮助