ciao!
essendo in react ho risolto usando useEffect e useState:
il mio problema era adattarlo a react senza usare le classi.codice:export default function Home() { const classes = useStyles(); const [books, setBooks] = useState([]); useEffect(() => { async function getBooks() { const result = await axios.get(BOOK_ALL); setBooks(result.data.books) } getBooks(); }, []); return ( <Paper className={classes.root}> <Table className={classes.table} size="small"> <TableHead> <TableRow> <StyledTableCell>Dessert (100g serving)</StyledTableCell> <StyledTableCell align="right">Calories</StyledTableCell> <StyledTableCell align="right">Fat (g)</StyledTableCell> <StyledTableCell align="right">Carbs (g)</StyledTableCell> <StyledTableCell align="right">Protein (g)</StyledTableCell> </TableRow> </TableHead> <TableBody> {books.map(row => ( <StyledTableRow key={row.id}> <StyledTableCell component="th" scope="row"> {row.title} </StyledTableCell> <StyledTableCell align="right">{row.author}</StyledTableCell> <StyledTableCell align="right">{row.editor}</StyledTableCell> <StyledTableCell align="right">{row.price}</StyledTableCell> <StyledTableCell align="right">{row.isbn}</StyledTableCell> </StyledTableRow> ))} </TableBody> </Table> </Paper> ); }
in effetti ero stato un pò vago.
ma girando ho fatto la ricerca giusta e trovato la situazione più corretta nel mio caso!
grazie cmq!
![]()

Rispondi quotando