from this function, How can I convert "this.state" to use in functional.
const handleDayClick = (day) => {
const range = DateUtils.addDayToRange(day, this.state);
setRange(range)
}
If you used useState
like this
const [range, setRange] = useState({});
then you need to use another variable name in the handle function.
const handleDayClick = (day) => {
const newRange = DateUtils.addDayToRange(day, range);
setRange(newRange);
}
this pointer doesn't work in functional component and you have to use hooks, so add this line
const [range, setRange] = React.useState({});
Then change this.state to range
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.