简体   繁体   中英

How to render a parent component upon clicking a child component in React?

I have three components each one being a parent of the other. I want to render the entire parent component upon clicking a child component. What is the correct way to achieve this?

You can update state of parent component from child component. Parent will then re-render automatically.

Or

You can pass forceUpdate method of parent component as a prop to child component. Whenever child component will call that method (eg on onClick handler), parent will re render.

Reference:

https://reactjs.org/docs/react-component.html#forceupdate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM