JavaScript TypeError:无法添加属性_id,对象不可扩展
我定义了一个HOC React组件并将其保存为一个tsx文件JavaScript TypeError:无法添加属性_id,对象不可扩展,javascript,reactjs,Javascript,Reactjs,我定义了一个HOC React组件并将其保存为一个tsx文件 const Hoc = WrappedComponent => class extends WrappedComponent { constructor(props, context) { super(props, context) this.__id = '' } } 一旦将其交付给编译器,就会抛出错误 TypeError: Cannot add property __id, object is n
const Hoc = WrappedComponent => class extends WrappedComponent {
constructor(props, context) {
super(props, context)
this.__id = ''
}
}
一旦将其交付给编译器,就会抛出错误
TypeError: Cannot add property __id, object is not extensible
错误来自为
WrappedComponent
参数传递的任何参数。以下内容不会引发:const Hoc=WrappedComponent=>类扩展WrappedComponent{constructor(props,context){super(props,context);this.\uu id='';}
然后new Hoc(class{})
错误来自为WrappedComponent
参数传递的任何参数。以下内容不会引发:const Hoc=WrappedComponent=>类扩展WrappedComponent{constructor(props,context){super(props,context);this.\uu id='';}代码>然后新建Hoc(类{})