Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

103
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!