老师您好,既然能在constructor中初始化state的值,为什么 this.state.isOpen = false的写法会报错。
constructor(props: Props) {
super(props);
this.state.isOpen = false;//error Cannot assign to ‘isOpen’ because it is a read-only property.
this.state =
{
isOpen: false,
};
}
React18 精讲 + 结合 TS 实战 + 热门业务开发,获取必备技能
了解课程