We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Thank you @sergiodxa that was exactly what I was looking for to spin a few ideas into my mind!
My implementation for others:
import useSWR from 'swr'; import { useDebounce } from '../../../utils/hooks'; ... // inside my component render method const [search, setSearch] = useState(''); const debouncedSearch = useDebounce(search, 1000); const { data: res, isValidating } = useSWR( () => debouncedSearch ? `/api/suggestion?value=${debouncedSearch}` : null, Api.fetcher, ); ...
// useDebounce.js import { useState, useEffect } from 'react'; export default function useDebounce(value, delay) { const [debouncedValue, setDebouncedValue] = useState(value); useEffect(() => { const handler = setTimeout(() => { setDebouncedValue(value); }, delay); return () => { clearTimeout(handler); }; }, [value, delay]); return debouncedValue; }
Originally posted by @watadarkstar in vercel/swr#110 (comment)
The text was updated successfully, but these errors were encountered:
No branches or pull requests
My implementation for others:
Originally posted by @watadarkstar in vercel/swr#110 (comment)
The text was updated successfully, but these errors were encountered: