score:1

Accepted answer

you can define onchange event handler in the child component, set child's set there and call the callback passed from the parent in props from the function. here is example code:

class child extends react.component {
  constructor(props) {
    super(props);
    this.onselectchange = this.onselectchange.bind(this);
  }
  onselectchange(e) {
    const newvalue = e.target.value;
    this.props.onchange(newvalue );
    // set child state here
    this.setstate({searchid : newvalue })
  }
  render() {
    return (
      <div>
        <select onchange={this.onselectchange}>
          <option value="1">1</option>
          <option value="2">2</option>
        </select>
      </div>
    )
  }
}

class parent extends react.component {
  constructor(props) {
    super(props);
    this.somehandler = this.somehandler.bind(this);
  }
  somehandler(childvalue) {
    console.log(childvalue);
    this.setstate({ value: childvalue })
  }
  render() {
    return <child onchange={this.somehandler} />
  }
}

here is a working example on codesandbox.


Related Query

More Query from same tag