Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

135
Visualizações
Next.JS typescript pass getServerSideProps returned props to external component

I have this Index.js page which through serverSideProps return all consumptions represented by an interface from a mock up json file. My goal is to pass the result to a component which uses DataGrid to display data to users and allow them to modify the values

export const getServerSideProps: GetServerSideProps = async () => {
   const consumptionsData: Consumption[] = await consumptionService.getAll();
   return {
       props: {
           consumptionsData: consumptionsData,
       },
   }
}

export default ConsumptionsGrid;

interface

export interface Consumption {
   ConsumptionID: number;
   CastingID: number;
   Elemento1: number;
   Elemento2: number;
   Elemento3: number;
   Elemento4: number;
   Elemento5: number;
};

I pass the result in this way

function ConsumptionsGrid(props: JSX.Element) {
  const [tableData, setTableData] = React.useState<GridRowModel[]>([]);

  React.useEffect(() => setTableData(props.consumptionsData.map()), [props, setTableData]); <-- consumptions.Data throw the error
  ...other code
  return (
        <div style={{ height: 400, width: 'auto' }}>
            <DataGrid
                experimentalFeatures={{ newEditingApi: true }}
                columns={columns}
                rows={data}
                rowCount={rowCountState}
                loading={isLoading}
                rowsPerPageOptions={[25]}
                pagination
                {...rowsState}
                paginationMode="server"
                onPageChange={(page) => setRowsState((prev) => ({ ...prev, page }))}
                onPageSizeChange={(pageSize) =>
                    setRowsState((prev) => ({ ...prev, pageSize }))
                }
            />
        </div>
    );
}

export { ConsumptionsGrid };

consumptionsData as written above throw this error

any
Property 'consumptionsData' does not exist on type 'Element'.ts(2339)

my question now is how do I have to characterize the props when I pass the argument in the component to handle it as I want?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

the type of props isnt JSX.Element but Consumption[] So you will have something like this

function ConsumptionsGrid({consumptionsData}: Consumption[])
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda