Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Commit 3c2c4e4

Browse files
committed
change TodoApp and add useRelayEnvironment to it
1 parent 7f590c3 commit 3c2c4e4

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

example-hooks/ts/components/TodoApp.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ import TodoListFooter from "./TodoListFooter"
1616
import TodoTextInput from "./TodoTextInput"
1717

1818
import React from "react"
19-
import { graphql, RelayProp, useFragment } from "react-relay"
19+
import { graphql, useFragment, useRelayEnvironment } from "react-relay"
2020

2121
import { TodoApp_viewer$key } from "../__relay_artifacts__/TodoApp_viewer.graphql"
2222

2323
interface Props {
24-
relay: RelayProp
2524
viewer: TodoApp_viewer$key
2625
}
2726

2827
const TodoApp = (props: Props) => {
28+
const environment = useRelayEnvironment()
29+
2930
const viewer = useFragment(
3031
graphql`
3132
fragment TodoApp_viewer on User {
@@ -39,7 +40,7 @@ const TodoApp = (props: Props) => {
3940
)
4041

4142
const handleTextInputSave = (text: string) => {
42-
AddTodoMutation.commit(props.relay.environment, text, viewer)
43+
AddTodoMutation.commit(environment, text, viewer)
4344
}
4445

4546
const hasTodos = (viewer.totalCount || 0) > 0

example-hooks/ts/components/TodoList.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313
import MarkAllTodosMutation from "../mutations/MarkAllTodosMutation"
1414
import Todo from "./Todo"
1515

16-
import React from "react"
16+
import React, { ChangeEvent } from "react"
1717
import { graphql, useFragment, useRelayEnvironment } from "react-relay"
1818

1919
import { TodoList_viewer$key } from "../__relay_artifacts__/TodoList_viewer.graphql"
20-
import { ChangeEvent } from "react"
2120

2221
interface Props {
2322
viewer: TodoList_viewer$key

example-hooks/ts/components/TodoRoot.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ const TodoRoot = () => {
1717
{},
1818
)
1919

20-
// @ts-ignore
21-
return <TodoApp viewer={viewer} />
20+
return <TodoApp viewer={viewer!} />
2221
}
2322

2423
const TodoRootWrapper = () => {

0 commit comments

Comments
 (0)