Good day,
I'm new with react.js
I'm trying to create a basic data binding using onChange
of the input. The problem is, I'm assigning to object with it's properties. Not directly to the property.
Now I'm receiving the error Warning: A component is changing a controlled input of type text to be uncontrolled.
when I type-in a character in my inputs.
Here's my code:
interface IProps { }
interface IFloorInfo {
id: number
name: string,
type: string,
condition: string
}
interface IFloorInfoState {
floor: IFloorInfo
}
export default class Floors extends React.Component<IProps, IFloorInfoState> {
state: IFloorInfoState
constructor(props: any){
super(props)
this.state = {
floor: {
id: 0,
name: '',
type: '',
condition: ''
}
}
}
...
render() {
return (
<div>
<input type="text" value={this.state.floor.name} onChange={(e)=>this.inputChanges(e)} />
<input type="text" value={this.state.floor.type} onChange={(e)=>this.inputChanges(e)} />
<input type="text" value={this.state.floor.condition} onChange={(e)=>this.inputChanges(e)} />
</div>
)
}
}
Now this is my inputChanges
method that detects if there's a changes in the input
inputChanges = (e:any) => {
this.setState({ floor: e.target.value });
}
Thank you in advance.