我正试图找到解决问题的办法
setState
从
parent
child
promise
.
父母亲
component
是
class Parent extends React.Component {
constructor(props) {
super(props);
this.state = {
transition: false
};
}
handleTransition = () => {
this.setState(state => ({ transition: !state.transition }));
};
render() {
return <Child handleTransition={this.handleTransition} />;
}
}
this.props.handleTransition
将从
小孩
组成部分
像
class Child extends Component {
constructor(props) {
super(props);
this.state = {};
}
onSubmit = event => {
firebase
.doCreateUserWithEmailAndPassword(email, password)
.then(() => {
// Trigger this.props.handleTransition here
})
...
哪里
这个。道具。手柄转换
是想被触发的
then
属于
onSubmit
如果你需要更多的细节,请告诉我?我宁愿不使用图书馆或包来实现这一点,但如果它使生活更容易,我可以考虑。Redux可能是最好的选择,但我宁愿不这样做,除非必要。
this.props.handleTransition();
做这项工作但是
esLint
返回的错误为
Must use destructuring props assignmenteslint(react/destructuring-assignment)
我认为这种方法不是正确的方法。