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

104
Visualizações
ReactJS: Make select with result from two query

I'm trying to create a select in which I take datafrom two api, I compare these data and show the results in the select.

my select is a Paginate Select so I need to search if there are other data when i call API

const SelectAsyncPaginate = props => {
    const [realmScelto, setRealmScelto] = useState(null);
    const [listaRealm, setListaRealm] = useState([]);

    useEffect(() => {
        setRealmScelto(props.realmScelto);
    }, [props.realmScelto]);

    const loadOptions = async (searchQuery, loadedOptions, { page }) => {
        const response = await fetch(
            `${apiUrl}?page=${page}&size=20&deletedDate.specified=false${searchQuery.length > 3 ? `&appDesapplicazione.contains=${searchQuery}` : ''
            }`
        )

        const response2 = await fetch(
            `${apiUrlRealm}?page=${page}&size=20&deletedDate.specified=false`
        )
        const optionToShow = await response.json();
        const optionToShow2 = await response2.json();
        console.log("optionToShow1", optionToShow)
        console.log("optionToShow2", optionToShow2)


        const notPresent = optionToShow2.filter(ra => {
            return !optionToShow.some(rua => rua.realm.id === ra.id && rua.user.perCod === props.persona.perCod.perCod);
        });
        setListaRealm(previousListRealm => [...previousListRealm, ...notPresent]);
        console.log("listaRealm", listaRealm)

        return {
            options: listaRealm,
            hasMore: listaRealm.length >= 1,
            additional: {
                page: searchQuery ? 2 : page + 1,
            },
        };
    };

    const onChange = option => {
        if (typeof props.onChange === 'function') {
            props.onChange(option);
        }
    };

    return (
        <AsyncPaginate
            value={props.value}
            loadOptions={loadOptions}
            getOptionValue={option => option.realm.id}
            getOptionLabel={option => option.realm.realmId}
            onChange={onChange}
            isSearchable={true}
            placeholder="Seleziona Realm"
            additional={{
                page: 0,
            }}
        />
    );
};

If I use only one api call it works, the problem is when I call the second API because I have a loop of api calls and it not controll if there is another page and it never update the listaRealm

How can I do in your opinion??

What I would to obtain is like:

  1. API call (apiUrl)

1.1 Check if there is another page

  1. API call (apiUrlRealm)

2.2 Check if there is another page

  1. Compare the two results to obtain result
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