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

202
Visualizações
how to stop state change to render material-ui table in reactjs

the next part of codes are inside my app.js: I got this state:

const [open,setOpen] = useState(false)

which is used to determine if a material-ui Alert should appear on the screen for 3 second with this code:

useEffect(()=>{
     setTimeout(()=> {
        setOpen(false)
     },3000)
},[open])

and returned as:

<Collapse in ={open}>
  <Alert severity={severity}>
    {alertMessage}
  </Alert>
</Collapse>

setOpen sent to the component Table as prop

<Table
loading={loading}
data={data}
setAlertState={setOpen}
/>

the next parts are in Table.js: in table.js I am working with:

import{
 useGridApiRef,
 DataGridPro,
 GridOverlay,
 GridActionsCellItem,
 useGridState
} from '@mui/x-data-grid-pro';

when I click to edit the row and then save this function run(this is not the full function ofc):

const handleSaveclick = (id) =>async(event)=>{
   if(validate_edit())
   {
      apiRef.current.updateRow([{...row}]);
      handleAlert("success","Word edited!");
   } 

handleAlert:

const handleAlert = (severity,alertMessage)=>
{
   setSeverity(()=>severity);
   setAlertMessage(()=>alertMessage);
   setAlertState(()=>true);
}

well the problem is that my data grid table updates himself, but when the alert goes true/false the table returns to what was before.

how to handle this render? what I do wrong? thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Without a full example, it will be hard to solve.

Most of the time such bugs appear when you rerender the DataGrid. You have two solutions:

  • avoid rerendering. Can not be more precise without example
  • control the data you want to keep them up to date
about 4 years ago · Juan Pablo Isaza 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