skywhat
skywhat

Reputation: 15

how to rerender parent component when onclick event happend in child component?

I am pretty new to React. Here is my question. I have a dialog as the child component, there is a save button, when I clicked on save, write data into database. then I need to rerender the parent component. currently I can just refresh the web page to get the new data.

class Row extends React.Component{
return(<Dialog />);
}


class Dialog extends React.Component{
_save=()=>{write into database}
return(
<UIDialog onClick={this.save} />
);
}

Upvotes: 0

Views: 53

Answers (1)

Paolo Dell&#39;Aguzzo
Paolo Dell&#39;Aguzzo

Reputation: 1431

I think that the best way is to put the save function in your parent component. Why should Dialog know how to save, it's just a dialog :)

Pass a prop to Dialog component so the parent (Row is the parent) will write into database and do the necessary stuffs to know if Dialog should disappear.

Upvotes: 1

Related Questions