[英]Unable to pass updated state using react hooks
const [endDate, setEndDate] = useState("");
const getMinDate = () =>{
if(endDate ==="")
return "02/03/2020";
else
return "10/10/2020";
}
const selectStartDate = (value) =>{
setEndDate(value)
}
return (<>
<Select onChange={selectStartDate} />
<Calendar min-date={getMinDate()}/>
</>)
Im trying to change min-date params each time Select value changes as shown in the code but the value for min-date doesnt change on each time change我每次都尝试更改 min-date 参数 Select 值更改如代码所示,但 min-date 的值不会在每次更改时更改
onChange 方法应该返回一个event
,然后您可以在 selectStateDate 函数中使用event.target.value
解析该值。
const selectStartDate = (event) => setEndDate(event.target.value);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.