(props: { setPostId: Setter<number> })
| 70 | } |
| 71 | |
| 72 | function Posts(props: { setPostId: Setter<number> }) { |
| 73 | const state = createPosts() |
| 74 | |
| 75 | return ( |
| 76 | <div> |
| 77 | <h1>Posts</h1> |
| 78 | <div> |
| 79 | <Switch> |
| 80 | <Match when={state.status === 'pending'}>Loading...</Match> |
| 81 | <Match when={state.status === 'error'}> |
| 82 | <span>Error: {(state.error as Error).message}</span> |
| 83 | </Match> |
| 84 | <Match when={state.data !== undefined}> |
| 85 | <> |
| 86 | <div> |
| 87 | <For each={state.data}> |
| 88 | {(post: any) => ( |
| 89 | <p> |
| 90 | <a |
| 91 | onClick={() => props.setPostId(post.id)} |
| 92 | href="#" |
| 93 | style={ |
| 94 | // We can find the existing query data here to show bold links for |
| 95 | // ones that are cached |
| 96 | queryClient.getQueryData(['post', post.id]) |
| 97 | ? { |
| 98 | 'font-weight': 'bold', |
| 99 | color: 'green', |
| 100 | } |
| 101 | : {} |
| 102 | } |
| 103 | > |
| 104 | {post.title} |
| 105 | </a> |
| 106 | </p> |
| 107 | )} |
| 108 | </For> |
| 109 | </div> |
| 110 | <div>{state.isFetching ? 'Background Updating...' : ' '}</div> |
| 111 | </> |
| 112 | </Match> |
| 113 | </Switch> |
| 114 | </div> |
| 115 | </div> |
| 116 | ) |
| 117 | } |
| 118 | |
| 119 | function createPost(postId: Accessor<number>) { |
| 120 | return useQuery(() => ({ |
nothing calls this directly
no test coverage detected
searching dependent graphs…