Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
2 replies
batata

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])
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?
Was this page helpful?