import { ErrorBoundary, For, Suspense, createSignal } from 'solid-js' import { A } from '@solidjs/router' import { noop, useQuery, useQueryClient } from '@tanstack/solid-query' import type { Character } from '~/services/characters/types' import { charactersQueries } from '~/services/characters/queries' function CharacterItem(props: { char: Character onSelect: (id: number) => void }) { const queryClient = useQueryClient() const characterQuery = useQuery(() => ({ ...charactersQueries.detail(props.char.id), enabled: false, })) return (
  • { props.onSelect(props.char.id) }} onMouseEnter={() => { queryClient .query({ ...charactersQueries.detail(props.char.id), staleTime: 10 * 1000, // only prefetch if older than 10 seconds }) .catch(noop) }} >
    {props.char.id} - {props.char.name}{' '} details
  • ) } function SelectedCharacter(props: { id: number }) { const characterQuery = useQuery(() => ({ ...charactersQueries.detail(props.id), throwOnError: true, })) return
    {JSON.stringify(characterQuery.data, null, 2)}
    } export default function Example() { const [selectedChar, setSelectedChar] = createSignal(1) const charactersQuery = useQuery(() => ({ ...charactersQueries.list(), throwOnError: true, })) return (

    Hovering over a character will prefetch it, and when it's been prefetched it will turn bold. Clicking on a prefetched character will show their stats below immediately, and opening its details page will render it without a loading state.

    Characters

    Error: {error.message}}>
      {(char) => ( )}

    Selected Character

    ) }