(props: { postId: number; setPostId: Setter<number> })
| 102 | } |
| 103 | |
| 104 | function Post(props: { postId: number; setPostId: Setter<number> }) { |
| 105 | // You can even leave out the queryFn and just go straight into options |
| 106 | const state = useQuery<any>(() => ({ |
| 107 | queryKey: [`/posts/${props.postId}`], |
| 108 | enabled: !!props.postId, |
| 109 | })) |
| 110 | |
| 111 | return ( |
| 112 | <div> |
| 113 | <div> |
| 114 | <a onClick={() => props.setPostId(-1)} href="#"> |
| 115 | Back |
| 116 | </a> |
| 117 | </div> |
| 118 | <Switch> |
| 119 | <Match when={!props.postId || state.status === 'pending'}> |
| 120 | Loading... |
| 121 | </Match> |
| 122 | <Match when={state.status === 'error'}> |
| 123 | <span>Error: {(state.error as Error).message}</span> |
| 124 | </Match> |
| 125 | <Match when={state.data !== undefined}> |
| 126 | <> |
| 127 | <h1>{state.data.title}</h1> |
| 128 | <div> |
| 129 | <p>{state.data.body}</p> |
| 130 | </div> |
| 131 | <div>{state.isFetching ? 'Background Updating...' : ' '}</div> |
| 132 | </> |
| 133 | </Match> |
| 134 | </Switch> |
| 135 | </div> |
| 136 | ) |
| 137 | } |
| 138 | |
| 139 | render(() => <App />, document.getElementById('root') as HTMLElement) |
nothing calls this directly
no test coverage detected
searching dependent graphs…