use*_*776 3 typescript reactjs
我有这个组件:
class Logos extends React.Component<{}, LogosState> {
...
public constructor() {
super({});
...
}
}
Run Code Online (Sandbox Code Playgroud)
我从这里了解到,即使组件没有 props,我也确实需要将参数传递给 super。
https://github.com/DefinitelyTyped/DefinitelyTyped/pull/20987#issuecomment-339216734
我的结论是尝试上面的代码。但我收到警告:
Warning: Logos(...): When calling super() in `Logos`, make sure to pass up the same props that your component's constructor was passed.
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题呢?
我最终这样做了。在此之前发布的其他答案很有帮助,并引导我找到了这个解决方案,但并不完整:
class Logos extends React.Component<{}, LogosState> {
...
public constructor(props: {}) {
super(props);
...
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1585 次 |
| 最近记录: |