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

291
Visualizações
How make React admin's <SimpleFormIterator> behave as a stack on item addition (add item on top)?

I have an item with a nested list of items. I can edit these nested items individually using a <SimpleFormIterator> mixed with a <FormDataConsumer>. The issue is that when i insert a new item in the list, it becomes the last item. I would like it to be the first, and shift every other item down a slot.

Maybe something like using a custom with an addOnTop callback could help? But I don't see a way to make it work without rewriting the whole component from scratch.

<SimpleFormIterator
     addButton={<ListAddButton onClick={addOnTop??} />}
     removeButton={<ListRemoveButton />}
>
...
</SimpleFormIterator>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Maybe try with unshift(). Here is the link: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift

about 4 years ago · Juan Pablo Isaza Relatório

0

In the end I think I managed to solve doing something like this:

const form = useForm();
    const getData = useCallback(() => {
        const emptyArticle = {
            URL: "",
            title: "",
            image: "",
            eyelet: "",
            topic: "",
        };
        const { articles } = form.getState().values;
        if (!articles) return [emptyArticle];
        articles.pop();
        articles.unshift(emptyArticle);
        return articles;
}, [form]);

<SimpleFormIterator
    addButton={
        <ListAddButton onClick={() => form.change("articles", getData())} />
  }
    removeButton={<ListRemoveButton />}
    TransitionProps={{
        enter: false,
        exit: false,
        addEndListener: () => {},
    }}
>
<SimpleFormIterator/>

I'm not sure it is the best approach, but it seems to work, although there is currently a bug with this component that forces the use of "emptyArticle" instead of simply pushing "undefined".

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