(props: { setPostId: Setter<number> })
| 54 | } |
| 55 | |
| 56 | function Posts(props: { setPostId: Setter<number> }) { |
| 57 | // All you have to do now is pass a key! |
| 58 | const state = useQuery<any[]>(() => ({ queryKey: ['/posts'] })) |
| 59 | |
| 60 | return ( |
| 61 | <div> |
| 62 | <h1>Posts</h1> |
| 63 | <div> |
| 64 | <Switch> |
| 65 | <Match when={state.status === 'pending'}>Loading...</Match> |
| 66 | <Match when={state.status === 'error'}> |
| 67 | <span>Error: {(state.error as Error).message}</span> |
| 68 | </Match> |
| 69 | <Match when={state.data !== undefined}> |
| 70 | <> |
| 71 | <div> |
| 72 | <For each={state.data}> |
| 73 | {(post) => ( |
| 74 | <p> |
| 75 | <a |
| 76 | onClick={() => props.setPostId(post.id)} |
| 77 | href="#" |
| 78 | style={ |
| 79 | // We can use the queryCache here to show bold links for |
| 80 | // ones that are cached |
| 81 | queryClient.getQueryData(['post', post.id]) |
| 82 | ? { |
| 83 | 'font-weight': 'bold', |
| 84 | color: 'green', |
| 85 | } |
| 86 | : {} |
| 87 | } |
| 88 | > |
| 89 | {post.title} |
| 90 | </a> |
| 91 | </p> |
| 92 | )} |
| 93 | </For> |
| 94 | </div> |
| 95 | <div>{state.isFetching ? 'Background Updating...' : ' '}</div> |
| 96 | </> |
| 97 | </Match> |
| 98 | </Switch> |
| 99 | </div> |
| 100 | </div> |
| 101 | ) |
| 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…