import { Suspense, useEffect, useState } from 'react' import { ErrorBoundary } from './components/ErrorBoundary' import { Loader } from './components/Loader' export function App() { const [search, setSearch] = useState('') const [debouncedSearch, setDebouncedSearch] = useState('') useEffect(() => { const timeout = setTimeout(() => { setDebouncedSearch(search) }, 500) return () => { clearTimeout(timeout) } }, [search]) return (
{ setSearch(ev.target.value) }} type="text" value={search} /> }> An error occurred
}> ) } function HideList({ search, debouncedSearch, children, }: { search: string debouncedSearch: string children: React.ReactNode }) { if (search !== debouncedSearch) { // we want to hide as soon as the user starts typing and show // this triggers the Suspense tag above it in the tree throw new Promise(() => { // }) } return <>{children} }