This is the table body:
<tbody>
{this.state.composantInformation.map(composantInformation => {
return (
<tr key={composantInformation.id.toString()}>
<td>{composantInformation.nom_composant}</td>
<td>{composantInformation.categorie}</td>
<td>{composantInformation.description}</td>
<td>{composantInformation.ref}</td>
<td>
<NumericInput
min={0}
max={100}
value={composantInformation.qte}
onChange={this.onQuantiteChange}
/>
</td>
</tr>
);
})}
</tbody>;
This is the state:
this.state = {
produitInformation: [],
composantInformation: [],
produitId: 0,
produitQte: 0
};
This is where the Backend API request is made:
componentDidMount() {
getProduitDataFromDB()
.then(result => {
this.setState({
produitInformation: result.data
});
})
.catch(error => console.error("(1) Outside error:", error));
}
In the last column, when I click on Increment/Decrement, the value gets increased and then goes back to 0.
I believe this has something to do with the fact that I am using map to display the table data.
{
this.state.produitInformation.map(produitInformation => {
return (
<tr
key={produitInformation.id.toString()}
produitid={produitInformation.id.toString()}
onClick={this.onTableRowClick}
>
<td>{produitInformation.nom_produit}</td>
<td>{produitInformation.prix}</td>
<td>{produitInformation.categorie}</td>
<td>{produitInformation.description}</td>
<td>
<NumericInput
min={0}
max={100}
value={produitInformation.qte}
tablerow={5}
onChange={this.onQuantiteChange}
/>
</td>
</tr>
);
});
}
Since the value inside NumericInput is not associated directly with a state value. Any idea how to solve this?
