我在使用reactjs和继承时遇到了麻烦。这是我的代码设置:
//This is the base class, this works (File 1)
class Base extends React.Component {}
export default Base
//This is the firstchild, this also works (File 2)
class FirstChild extends Base{}
export default FirstChild
//This results in the above TypeError (File 3)
class SecondChild extends FirstChild{}
export default SecondChild
现在奇怪的是,如果我改变它:
class SecondChild extends Base
它有效。
我已经看过这篇文章了: reactjs giving error Uncaught TypeError: Super expression must either be null or a function, not undefined,但仍然没有解决方案。
我想要完成的是拥有一个具有一些功能的基本组件,另一个组件有点类似于基础但覆盖了一些功能。最后,构建在第二个组件上的第三个组件,但是再次覆盖了第一个子组件中的一些功能。
作为参考,我正在使用react:15.4.1
有什么建议吗?