import { useQuery } from '@tanstack/solid-query' import { resetErrorBoundaries } from 'solid-js' import { createSignal } from 'solid-js' import { For } from 'solid-js' import { Example } from './example' import { QueryBoundary } from './query-boundary' import type { Component } from 'solid-js' import { fetchPost } from '~/utils/api' export interface PostViewerProps { deferStream?: boolean sleep?: number simulateError?: boolean } export const PostViewer: Component = (props) => { const [simulateError, setSimulateError] = createSignal(props.simulateError) const [postId, setPostId] = createSignal(1) const query = useQuery(() => ({ queryKey: ['posts', postId()], queryFn: () => fetchPost({ postId: postId(), sleep: props.sleep, simulateError: simulateError() || (simulateError() !== false && postId() === 5), }), deferStream: props.deferStream, throwOnError: true, })) return (
{/* NOTE: without this extra wrapping div, for some reason solid ends up printing two errors... feels like a bug in solid. */}
loading post...
} errorFallback={(err, retry) => (
{err.message}
)} > {(posts) => ( {(post) => (
[post {postId()}] {post.title}

{post.body}

)}
)}
) }