(props: { setPostId: Setter<number> })
| 34 | } |
| 35 | |
| 36 | function Posts(props: { setPostId: Setter<number> }) { |
| 37 | const state = createPosts() |
| 38 | |
| 39 | return ( |
| 40 | <div> |
| 41 | <h1>Posts</h1> |
| 42 | <div> |
| 43 | <Switch> |
| 44 | <Match when={state.status === 'pending'}>Loading...</Match> |
| 45 | <Match when={state.status === 'error'}> |
| 46 | <span>Error: {(state.error as Error).message}</span> |
| 47 | </Match> |
| 48 | <Match when={state.data !== undefined}> |
| 49 | <> |
| 50 | <div> |
| 51 | <For each={state.data}> |
| 52 | {(post) => ( |
| 53 | <p> |
| 54 | <a |
| 55 | onClick={() => props.setPostId(post.id)} |
| 56 | href="#" |
| 57 | style={ |
| 58 | // We can access the query data here to show bold links for |
| 59 | // ones that are cached |
| 60 | queryClient.getQueryData(['post', post.id]) |
| 61 | ? { |
| 62 | 'font-weight': 'bold', |
| 63 | color: 'green', |
| 64 | } |
| 65 | : {} |
| 66 | } |
| 67 | > |
| 68 | {post.title} |
| 69 | </a> |
| 70 | </p> |
| 71 | )} |
| 72 | </For> |
| 73 | </div> |
| 74 | <div>{state.isFetching ? 'Background Updating...' : ' '}</div> |
| 75 | </> |
| 76 | </Match> |
| 77 | </Switch> |
| 78 | </div> |
| 79 | </div> |
| 80 | ) |
| 81 | } |
| 82 | |
| 83 | const getPostById = async (id: number): Promise<Post> => { |
| 84 | const response = await fetch( |
nothing calls this directly
no test coverage detected
searching dependent graphs…