使用 Material UI 5 和 Next.js 13 获取和渲染表格时出错

问题描述 投票:0回答:0

使用 material ui 和 nextjs 13 呈现服务器端的最佳方式

我有这段代码,但不是获取和呈现表格的最佳方式 最好的方法是什么?

import TableCell from '@mui/material/TableCell'; 
import TableRow from '@mui/material/TableRow';


export const getOrders  = async () => {
    try {
const response = await fetch('https://miurl.com', {cache: 'no-store'});
        const data = await response.json();
        return data;
    } catch (error) {
        console.log(error);
    }
};
 


export const RenderOrders = async function RenderOrders() {
const pedidos = await getOrders ();
 
    return pedidos.pedido.map((row) => (
        <TableRow
            key={row.id}
            sx={{ '&:last-child td, &:last-child th': { border: 0 } }}
        >
            <TableCell component="th" scope="row">
                {row.codt}
            </TableCell>
            <TableCell align="center">{row.name}</TableCell>
            <TableCell align="center">{row.cc}</TableCell>
            <TableCell align="center">{row.address}</TableCell>
        <TableCell align="center">{row.ud}</TableCell>
        </TableRow>
      ));    
} as unknown as () => JSX.Element

 
reactjs material-ui fetch nextjs13
© www.soinside.com 2019 - 2024. All rights reserved.