在父类中调用save按钮调用方法时遇到一些问题 保存在儿童班。我需要找到一个解决方案来调用保存功能 父组件
class Parent extends React.Component{
render(){
return(
<Child />
<button onClick={Child.alert()}>save</button>
**// this button should call alert function now.**
)
}
}
export default Parent
// child component
class Child extends React.Component{
alert= () => {
console.log('child's alert called')
}
render(){
return(
<button onClick={this.alert()}>Save</button>
**// this is calling alert right now**
)
}
}
export default Child
**//when save button of the parent class called, it should call the alert
method in the child class.**