score:3

Accepted answer
var ParentComponent = React.createClass({
    update: function() {
        console.log("updated!");
    },
    render: function() {
      <ChildComponent callBack={this.update} />
    }
})

var ChildComponent = React.createClass({
    preupdate: function() {
        console.log("pre update done!");
        this.props.callback()
    },
    render: function() {
        <button onClick={this.preupdate.bind(this)}>click to update parent</button>
    }
})

score:0

preupdate: ()=> {
        console.log("pre update done!");
    }

score:2

const AlertModal = (props) =>{

const goBack = () => {
    props.callBack('hello');// can pass callback data here
}
return (
    <>
      <div>
      <Button className="btn-round" color="danger"   onClick={goBack}>
        Go Back
            </Button>
      </div>
    </>
);
}

export default AlertModal;

Related Query

More Query from same tag