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

310
Visualizações
Using useSortableData based on useMemo() after data update in React app

I've made application based on this example

https://codesandbox.io/embed/table-sorting-example-ur2z9?fontsize=14&hidenavigation=1&theme=dark

But also I need data update in table (adding, removing)

I use

const { items, requestSort, sortConfig } = useSortableData(data.items, sortObj);
const [datarows, setDatarows] = useState({})

useEffect(() => {
setDatarows(items)
});

const updateData = (row, useropt) => {
...
/* here fetching some data */
...
setDatarows(rows2);
}

But after data update useSortableData function is sorting initially added data How to make useSortableData use updated data?

I've tried

const [datarows, setDatarows] = useState(data.items)
const { items, requestSort, sortConfig } = useSortableData(datarows, sortObj);

But in this case I get

Unhandled Runtime Error

TypeError: Invalid attempt to spread non-iterable instance. In order to be iterable, non-array objects must have a Symbol.iterator method.

Thanks

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

0

Looking at the code you provided it looks like useSortableData is has items as a dependency in the useMemo of the sortedItems. Meaning that any changes to data.items will result in a recalculation of the sorted items.

You have not provided the piece of code from where you get data.items, therefore this is the extent of what I can help with

enter image description here

about 4 years ago · Juan Pablo Isaza Relatório

0

Solved.

Data loading and changing left in main Component. The table and sorting const { items, requestSort, sortConfig } = useSortableData(data.items, sortObj); moved to other component

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