Open History to see the last commit
function Todos() {
const [filter, setFilter] = useState('')
const { data } = useQuery({
queryKey: ['todos', filter],
queryFn: () => fetchTodos(filter),
// β¬οΈ disabled as long as the filter is empty
enabled: !!filter,
})
return (
<div>
// π applying the filter will enable and execute the query
<FiltersForm onApply={setFilter} />
{data && <TodosTable data={data} />}
</div>
)
}
import { skipToken, useQuery } from '@tanstack/preact-query'
function Todos() {
const [filter, setFilter] = useState<string | undefined>()
const { data } = useQuery({
queryKey: ['todos', filter],
// β¬οΈ disabled as long as the filter is undefined or empty
queryFn: filter ? () => fetchTodos(filter) : skipToken,
})
return (
<div>
// π applying the filter will enable and execute the query
<FiltersForm onApply={setFilter} />
{data && <TodosTable data={data} />}
</div>
)
}