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

164
Visualizações
Maximum call stack size exceeded due to recursive function

I'm trying to populate data from an array through a recursive function, and this function would get called upon each time the data or search value is updated. I understand that to avoid call stack being exceeded a base case should be established, but in my case I thought I had that covered. I have also tried out using an increment counter to reset the call stack when it hits a certain value, but that didn't seem to work.

How can I avoid the maximum call stack issue from occurring? Any help is greatly appreciated, thanks.

const filteredTreeData = useMemo(() => {
    function getObjects(array, target) {
      return array?.reduce((r, { title, key, children = [] }) => {
          if (title.toLowerCase().includes(target.toLowerCase())) {
              // Check and loop their children
              if (children?.length) {
                getObjects(children, target)
              } else {
                r?.push({ title, key });
              }
          }
          else return;
          children = getObjects(children, target);
          if (children?.length) {
             r?.push({ title, key, children })
          }
          return r;
    }, []);
  }
  return search.length > 0 ? getObjects(treeData, search) : treeData
}, [treeData, search])
about 4 years ago · Juan Pablo Isaza
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