我让它在 classtwo 中从 classone 调用 getValue 工作,但是还有另一种方法吗?有没有更简单的方法从 classtwo 获取 this.state.value?
我尝试将静态 getValue 设置为静态,但它总是给我一个错误。任何人都可以帮忙吗?
谢谢!
class ClassOne extends React.Component {
constructor(props) {
super(props);
this.state = {
classtwo: new ClassTwo(),
};
}
CallGetValue(){
this.state.classtwo.getValue();
}
}
class ClassTwo extends React.Component {
constructor(props) {
super(props);
this.state = {
value: 100,
};
}
getValue(){
return this.state.value;
}
}