forked from relay-tools/relay-compiler-language-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TodoRoot.tsx
38 lines (32 loc) · 981 Bytes
/
TodoRoot.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import React from "react"
import { graphql } from "react-relay"
import {
loadAppInitialStateQuery,
usePreloadedAppInitialStateQuery,
} from "../__relay_artifacts__/appInitialStateQuery.graphql"
import { useTodoRootQuery } from "../__relay_artifacts__/TodoRootQuery.graphql"
import TodoApp from "./TodoApp"
graphql`
query TodoRootQuery($first: Int, $last: Int) {
viewer {
...TodoAppData @arguments(first: $first, last: $last)
}
}
`
const TodoRoot: React.FC<{ isAppending: boolean }> = ({ isAppending }) => {
const { viewer } = useTodoRootQuery(
isAppending ? { last: 10 } : { first: 10 },
)
return <TodoApp frag={viewer!} />
}
const TodoRootWrapper: React.FC<{
queryRef: ReturnType<typeof loadAppInitialStateQuery>
}> = ({ queryRef }) => {
const result = usePreloadedAppInitialStateQuery(queryRef)
return (
<>
{result.viewer && <TodoRoot isAppending={result.viewer?.isAppending} />}
</>
)
}
export default TodoRootWrapper