Skip to content

Commit

Permalink
fix: TodoListのuseEffect無限ループを修正(useCallbackでfetchTodosをメモ化)
Browse files Browse the repository at this point in the history
  • Loading branch information
User committed Jan 12, 2026
1 parent 99a5f95 commit 546577f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions components/TodoList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import { useEffect, useState } from 'react'
import { useCallback, useEffect, useState } from 'react'
import TodoItem from './TodoItem'

export interface Todo {
Expand All @@ -17,7 +17,7 @@ export default function TodoList() {
const [isLoading, setIsLoading] = useState(true)
const [error, setError] = useState<string | null>(null)

const fetchTodos = async () => {
const fetchTodos = useCallback(async () => {
try {
setIsLoading(true)
const response = await fetch('/api/todos')
Expand All @@ -34,7 +34,7 @@ export default function TodoList() {
} finally {
setIsLoading(false)
}
}
}, [])

useEffect(() => {
fetchTodos()
Expand Down

0 comments on commit 546577f

Please sign in to comment.