Tengo un problema cuando intento mapear mis datos. Quiero un nombre de empresa alcance en proveedor en productos. ¿Cómo puedo arreglarlo?
{products.map((repo) => ( <div style={{ backgroundColor: "#c1d3d4", marginTop: 50, display: "flex", flexDirection: "column", minWidth: 1000, paddingLeft: 50, marginLeft: 400, paddingRight: 30, paddingBottom: 12, borderRadius: 15, }} span={24} > <p style={{ flex: 1, fontWeight: "bold", fontSize: 26 }}> {repo.name} </p> <p style={{ fontWeight: "bold", fontSize: 14 }}>{repo.supplier.companyName}</p> <p style={{ fontWeight: "bold", fontSize: 14 }}> {repo.quantityPerUnit} </p> <div style={{ display: "flex", flexDirection: "row", justifyContent: "space-between", alignContent: "flex-end", }} > <p style={{ fontSize: 20, fontWeight: "800", color: "green", alignSelf: "flex-end", }} > {repo.unitPrice.toFixed(2)} </p> <Button type="primary" onClick={() => AddCart(repo)}> Sepete Ekle </Button> </div> </div> ))}este es un error de mensaje de error
esto es datos:
https://northwind.vercel.app/api/products
editar:
@Tim Roberts encontró la solución. Solo algunos elementos tienen proveedor por lo que otros no lo tienen. Tomé el mensaje de error cuando intento el mapa. Entiendo ahora.
Creo que el error se debe a que en algunos datos de la api no existe el accesorio del proveedor.
Tu codigo
<p style={{ fontWeight: "bold", fontSize: 14 }}>{repo.supplier.companyName}</p>Solución posible
<p style={{ fontWeight: "bold", fontSize: 14 }}>{repo.supplier && repo.supplier.companyName}</p>