Skip to content

Commit

Permalink
focus after add todo
Browse files Browse the repository at this point in the history
  • Loading branch information
ZupaFly committed Nov 30, 2024
1 parent e1f9607 commit 81d8fc5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ export const App: React.FC = () => {
setTodos(prevTodos => [...prevTodos, newTodo]);
setTempTodo(null);
setError('');
inputRef.current?.focus();
} catch {
setError('Unable to add a todo');
setTempTodo(null);
Expand All @@ -90,6 +89,10 @@ export const App: React.FC = () => {
}
};

useEffect(() => {
inputRef.current?.focus();
}, [todos]);

const handleDeleteTodo = async (todoId: number) => {
sethaveId(prev => [...prev, todoId]);
try {
Expand Down Expand Up @@ -128,6 +131,7 @@ export const App: React.FC = () => {
setError('Unable to delete completed todos');
} finally {
sethaveId([]);
inputRef.current?.focus();
}
};

Expand Down

0 comments on commit 81d8fc5

Please sign in to comment.