我需要继承状态。我可以继承国家吗?当我这样做时,我得到一个空状态。
class Example extends Component {
constructor(props) {
super();
this.state = {
param1:
};
}
...
}
class Example2 extends Example {
render() {
return (
{this.state.param1} // empty
)
}
}
最佳答案
您可以按如下方式扩展状态:
constructor(props) {
super(props)
this.state = {
...this.state,
extraStuff: '',
}
}
关于javascript - 扩展状态 react ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51767555/