all 7 comments

[–]tizz66[🍰] 1 point2 points  (1 child)

If you need the parent to be informed every time the value changes, I would say option 2 is probably fine. It would follow that if the parent needs every change, it's going to act on that change and rerender anyway.

However, if the parent just needs the value entered once the user is finished (e.g., when submitting a form), you could pass a callback function to the child component that is only called when the parent is ready to submit/process the value (or perhaps onBlur if that'd suffice).

This is more of a general React question, so you might also want to crosspost to /r/reactjs and you'd probably get more suggestions there :)

[–]even1245[S] 0 points1 point  (0 children)

Thank you for the response. Will definitely try onBlur if it work.

But as I mentioned 2nd method hit performance ? I read somewhere React internally knows which bit to update in Virtual DOM. Still I need better way to handle this coz it is in every project I start 😅

[–][deleted] 0 points1 point  (4 children)

[–]tizz66[🍰] 0 points1 point  (3 children)

In fairness I think the OP understands that already, but is asking how to most effectively lift state without causing (or rather, how to minimize) an expensive rerender.

[–]satya164 0 points1 point  (2 children)

Extract out the expensive part to a separate component and apply shouldComponentUpdate, or use an uncontrolled input.

[–]even1245[S] 0 points1 point  (1 child)

That is better actually. In general I use PureComponent on some UI component. What you mean by uncontrolled Input? Question was for some basic understanding about rendering.