File tree Expand file tree Collapse file tree 1 file changed +8
-10
lines changed Expand file tree Collapse file tree 1 file changed +8
-10
lines changed Original file line number Diff line number Diff line change @@ -8,11 +8,16 @@ import TodoList from "@/components/todo/todo-list";
88import { useAsyncCall } from "@/hooks/use-async-call" ;
99import { addTodo , getTodos , toggleTodo } from "@/libs/apis/todo" ;
1010import styles from "@/styles/home.module.css" ;
11- import { useEffect , useMemo , useState } from "react" ;
11+ import { useMemo , useState } from "react" ;
1212
13- export default function Home ( ) {
13+ export async function getServerSideProps ( ) {
14+ const todos = await getTodos ( ) ;
15+ return { props : { todos } } ;
16+ }
17+
18+ export default function Home ( { todos : initialTodos } ) {
1419 const [ inputValue , setInputValue ] = useState ( "" ) ;
15- const [ todos , setTodos ] = useState ( [ ] ) ;
20+ const [ todos , setTodos ] = useState ( initialTodos ?? [ ] ) ;
1621 const [ isLoading , execute ] = useAsyncCall ( ) ;
1722
1823 const canAdd = useMemo ( ( ) => inputValue . trim ( ) . length > 0 , [ inputValue ] ) ;
@@ -51,13 +56,6 @@ export default function Home() {
5156 } ) ;
5257 } ;
5358
54- useEffect ( ( ) => {
55- execute ( async ( ) => {
56- const fetchedTodos = await getTodos ( ) ;
57- setTodos ( fetchedTodos ) ;
58- } ) ;
59- } , [ ] ) ;
60-
6159 return (
6260 < >
6361 < GlobalNavBar />
You can’t perform that action at this time.
0 commit comments