问题描述
//=> my state
const [date,setDate] = useState({ year: "",month: "",full: "" });
///=> here is to change state situation after month changed
else if (target.name === "cardMonth") {
target.value = formatMonthDate(target.value);
setDate({ ...date,month: target.value });
}
//=> here is my select option area to select date
<div className="form-group">
<div className="input-group mb-3">
<select
className="custom-select"
name="cardMonth"
onChange={(e) => handleInputChange(e)}
onFocus={(e) => handleInputFocus(e)}
>
{months.map((month) => (
<option value={month} key={month}>
{month}
</option>
))}
</select>
</div>
</div>
问题是,当我第一次选择一个月时,它不能出现在状态中,但是当我选择一个新日期时,我的状态就变成了第一状态。不久状态就跟着变化退了一步。例如:我第一次选择一月,在我的州并不受欢迎。以后我选择2月,然后在1月而不是2月见州。如果我选择一个新的,那么我将只看到1月和2月。就像这样,我几乎花了一天的时间。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)