Search code examples
reactjsreact-typescript

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

  • 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