diff --git a/examples/react-todomvc/src/App.tsx b/examples/react-todomvc/src/App.tsx index 44a301a1e..7d0caccaa 100644 --- a/examples/react-todomvc/src/App.tsx +++ b/examples/react-todomvc/src/App.tsx @@ -1,46 +1,29 @@ -import { useDocument, JSONArray, JSONObject } from '@yorkie-js/react'; -import 'todomvc-app-css/index.css'; +import { JSONArray, JSONObject, useDocument } from '@yorkie-js/react'; import Header from './Header'; import MainSection from './MainSection'; import { Todo } from './model'; import './App.css'; +import 'todomvc-app-css/index.css'; + /** * `App` is the root component of the application. */ export default function App() { const { root, update, loading, error } = useDocument<{ todos: JSONArray; - }>( - import.meta.env.VITE_YORKIE_API_KEY, - `react-todomvc-${new Date().toISOString().substring(0, 10).replace(/-/g, '')}`, - { - todos: [ - { id: 0, text: 'Yorkie JS SDK', completed: false }, - { id: 1, text: 'Garbage collection', completed: false }, - { id: 2, text: 'RichText datatype', completed: false }, - ], - }, - { - rpcAddr: import.meta.env.VITE_YORKIE_API_ADDR, - }, - ); - - if (loading) { - return
Loading...
; - } + }>(); - if (error) { - return
Error: {error.message}
; - } + if (loading) return
Loading...
; + if (error) return
Error: {error.message}
; const actions = { addTodo: (text: string) => { update((root) => { root.todos.push({ id: - root.todos.reduce((maxId, todo) => Math.max(todo.id, maxId), -1) + + root.todos.reduce((maxID, todo) => Math.max(todo.id, maxID), -1) + 1, completed: false, text, diff --git a/examples/react-todomvc/src/MainSection.tsx b/examples/react-todomvc/src/MainSection.tsx index 2e503cc54..632be24fa 100644 --- a/examples/react-todomvc/src/MainSection.tsx +++ b/examples/react-todomvc/src/MainSection.tsx @@ -16,9 +16,8 @@ interface MainSectionProps { actions: { [name: string]: Function }; } -export default function MainSection(props: MainSectionProps) { +export default function MainSection({ todos, actions }: MainSectionProps) { const [filter, setFilter] = useState('SHOW_ALL'); - const { todos, actions } = props; const filteredTodos = todos.filter(TODO_FILTERS[filter]); const completedCount = todos.reduce((count, todo) => { return todo.completed ? count + 1 : count; @@ -37,17 +36,15 @@ export default function MainSection(props: MainSectionProps) { onChange={actions.completeAll as ChangeEventHandler} />