所以这个函数更新这个状态数组:
let [Produits, setProduit] = useState(JSON.parse(Devis.produits))
let changeQte = (id, e) => {
let produittable = Produits;
produittable.forEach((p) => {
if (p.id == id) {
p.quantityAchete = parseInt(e.target.value);
}
});
setProduit(produittable);
};
数组确实更新没有任何问题,但更改没有重新渲染
{console.log('rendering') ,Produits.map((p) => (
<div key={p.id} className="product_column flex_center">
<div className="productItem">{p.nom}</div>
<div className="productItem">{p.category}</div>
<div className="productItem">{p.prix_vente} DA</div>
<input
onChange={(e) => changeQte(p.id, e)}
type="number"
name="qte"
value={p.quantityAchete}
/>
如您所见,我正在登录控制台以检查该行是否正在执行,并且确实如此!但呈现的值不会更新!