是否可以立即使用状态值,例如:
const [counter, setCounter] = useState(0);
const onChange = (value = 42) => {
setCounter(value); //value === 42
props.onChange(counter); // counter === 0
}
不使用新变量,例如
const onChange = (value = 42) => {
const val = value;
setCounter(val); //val === 42
props.onChange(val);
}