Use parent component to pass initial value to child without relying on state ReactJS

Hey even though you may do this better way if I understood correctly I think you can achieve what you want by just using:

this.props.value

on B Component:

<input defaultValue={this.props.value} onChange={this.onChange}/>

and then when you handle update just pass in event.target.value to parent (A component)

I’m not 100% sure if that’s what you are asking but here’s example:

https://codepen.io/pegla/pen/qBNxqBd?editors=1111

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top