score:3

Accepted answer

you should use uselazyquery hook in this case. it is very useful for things that happen at an unknown point in time, such as in response to a user's search operation.

how about if you call use your hook on the top of your function and just call it inside the useeffect hook.

const [search, { data }] = uselazyquery(search, {
        variables: {  "str": searchedtext },
        pollinterval: 500,
    });

react.useeffect(() => {
        if (searchedtext) 
            search() // function for executing the query

        if (data) 
            setsuggestions(data)

    }, [searchedtext])

as you see, uselazyquery handles fetching data in a synchronous way without any promises.


Related Query

More Query from same tag