Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

react with typescript and props

In order to update a prop inside a child component, I was passing a function that updates this prop as a prop to the child component. So the question is that a good approach? and
what is the best approach to update a prop from a child component when using Typescript ?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

this is called lifting state up and it is a common approach in React to keep components in sync,

it works by moving the state to the parent component (so you can share it with other siblings) and then passing the state and the event handler as a props

for more details see the official react docs
https://reactjs.org/docs/lifting-state-up.html

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading