trpc useQuery fetch on demand

const [query, setQuery] = useState<string>('')
const [suggestions, setSuggestions] = useState<Shop[] | null>()

const { error, data, refetch } = trpc.shops.getByName.useQuery(query)

useEffect(() => {
const getData = setTimeout(() => {
refetch()
setSuggestions(data)
}, 500)
return () => clearTimeout(getData)
}, [query])
const [query, setQuery] = useState<string>('')
const [suggestions, setSuggestions] = useState<Shop[] | null>()

const { error, data, refetch } = trpc.shops.getByName.useQuery(query)

useEffect(() => {
const getData = setTimeout(() => {
refetch()
setSuggestions(data)
}, 500)
return () => clearTimeout(getData)
}, [query])
javascript so in this code the useQuery is firing everytime query changes, i dont want that, i just want to fetch the data in the getdata function. Is there a way to do it?
2 Replies
cje
cje2y ago
trpc.shops.getByName.useQuery(query, { enabled: false })
batata
batataOP2y ago
oh okay, i was trying {manual: true}, thank you!!
Want results from more Discord servers?
Add your server