[英]i have problem with converting function in class component to functional
from this function, How can I convert "this.state" to use in functional.从这个函数,我如何转换“this.state”以在函数中使用。
const handleDayClick = (day) => {
const range = DateUtils.addDayToRange(day, this.state);
setRange(range)
}
If you used useState
like this如果你像这样使用
useState
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然后将this.state更改为range
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.