use-http icon indicating copy to clipboard operation
use-http copied to clipboard

Query params on get request

Open everythingspirals opened this issue 4 years ago • 3 comments

Is there a way for me to pass query params to a get() function, i.e like axios.get(url, options)?

everythingspirals avatar Dec 04 '20 07:12 everythingspirals

you should be able to do get('?my=query&params=cool')

iamthesiz avatar Dec 07 '20 21:12 iamthesiz

hey u can build ur url in a useMemo hook and then pass to useFetch hook

const url = useMemo(() => buildUrl(url, {params}) ,[params]) const { get } = useFetch(url, options)

get() // ur get method will be built each time the url changes

also read https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams

grinsteindavid avatar Feb 20 '21 18:02 grinsteindavid

Should be fine to do it that way too.

const url = useMemo(() => buildUrl(url, {params}) ,[params])
const { data, loading } = useFetch(url, [])

iamthesiz avatar Feb 22 '21 22:02 iamthesiz