I am very new to ReactJS, I'm trying to type inside the input field however, it is overriding only 1 number then the cursor disappears, I want the curosor ro stay so I can type as much numbers as I want. I've watched several tutorials however non of them worked in my case. Appreciate your assistance regarding this matter
this.handleInputChange = this.handleInputChange.bind(this)
this.state = {
coordinatesList: [
[29.294957293, 30.1027401502],
[30.193056150, 26.1047492638]
]
}
//coordinatesList returns a an array list of arrays with 2 index
// I want to display each index seperatly, that's why I used item[0]
<SortableContainer coordinatesList={this.state.coordinatesList} drag=
{this.handleDragging}>
{this.state.coordinatesList.map((item, index) => (
<SortableItem
key={item}
index={index}
className="sortable-item"
>
<SortIcon />
<input onChange={(e) => this.handleInputChange(e,
index)} type="text" value={item[0]} />
</SortableItem>
))}
</SortableContainer>
handleInputChange(e, index){
let updatedState = [...this.state.coordinatesList];
updatedState[index] = [Number(e.target.value),
this.state.coordinatesList[index][1]]
this.vectorLayer.clear();
apiRegistry
.getApis(["Feature"])
.then(([Feature]) => {
var feature = new Feature({
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [this.state.coordinatesList]
},
"properties": {
}
})
this.vectorLayer.addFeature(feature);
this.setState({
coordinatesList: updatedState
})
});
}
handleInputChangechangesthis.state.coordinatesListto be a string but you're mapping over it as if it were an array.value={"x: " + item[0]}this is also probably not going to do what you expect. You should make a label for the input instead.coordinatesList? You're going to need to provide more context, after the update I still dont see how this could work, and you're still changing the data type ofcoordinatesListin the change handler.