I am new to reactjs.
What is the proper way to pass the parent value to child setState, I am having error says below, and I am unable to change input value, the value looks correct but unable to be changed.
"is changing an uncontrolled input of type text to be controlled. Input elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the component"
export default class parent extends React.Component {
constructor (props) {
super(props);
this.state = {
title: ''
}
}
updateFun(){
this.setState({title: 'Parents title'});
}
render() {
return (
<div>
<button onClick={() => this.updateFun()}> Update </button>
<Child title = {this.state.title}/>
</div>
)
}
}
export default class Child extends React.Component {
constructor (props) {
super(props);
this.state = {
title: ''
}
}
render() {
return (
<div>
<input
id="title"
type="text"
value={this.props.title}
/>
</div>
)
}
}