I am just getting started with React and not able to figure this out.
<Select>
<Search term={this.state.filename} />
</Select>
Select component is for selecting a file, I want to set the initial value of input text inside the Search component to be the filename.
Here is the Search component
<form onSubmit={this.handleSubmit}>
<input
type="search"
value={this.props.term}
onChange={this.handleChange}
/>
</form>
Now, whenever user tries to change the value of input from the initial value set by the parent, I set the state of the child with the new input value but this triggers re-render of the child which resets the input value. What is the correct way around this?
What I am currently thinking is if I assign the value of input like this value={this.props.term}
, then changing the state will trigger re-render of the child with the filename as the default value and user will be able to edit it.