So I update my state in a component and then pass the new props into the child but the child isn't updating correctly and the defaultValue of the input is not changing. At first I thought it might be because I am using this.props so begun using this.states and applying the new props there first but doesn't seem to be working.
Parent Component
this.state.newDetails == null ? '' :
<NewDetailsView details={this.state.newDetails} />
Child component:
import React, { Component } from 'react';
class NewDetailsView extends Component {
constructor(props) {
super(props);
this.state = {
details: (this.props.details!= null) ? this.props.details: null
}
}
componentWillReceiveProps(nextProps) {
this.setState({ details: nextProps });
this.forceUpdate();
}
render() {
return (
<div>
<input type="text" defaultValue={this.state.details.id} />
</div>
);
}
}
export default NewDetailsView ;
Solution Code:
Pending...