【发布时间】:2021-12-10 05:42:57
【问题描述】:
我正在尝试将this demo 转换为函数组件。我正在关注these steps,但我遇到了以下问题:
班级版本:
this.appointmentForm = connectProps(AppointmentFormContainer, () => {
const {
editingFormVisible,
editingAppointment,
data,
addedAppointment,
isNewAppointment,
previousAppointment,
} = this.state;
函数转换尝试:
const [appointmentForm, setappointmentForm] = useState({});
setappointmentForm(connectProps(AppointmentFormContainer, () => {
const {
editingFormVisible,
editingAppointment,
data,
addedAppointment,
isNewAppointment,
previousAppointment,
};
这个版本的错误(尝试了几个)是:“解析错误:'常量声明'需要一个初始化值。”它指的是 setappointmentForm 下的行中的 const 但摆脱它也是不正确的。如果需要整个代码,我会放它,但它很长。有什么想法吗?
【问题讨论】:
标签: javascript reactjs react-hooks es6-class