Skip to content

Commit

Permalink
added reduce version
Browse files Browse the repository at this point in the history
  • Loading branch information
minimal005 committed Dec 24, 2024
1 parent f825975 commit 5c1961c
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/components/Form.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import React, { useContext, useEffect, useRef } from 'react';
import React, { useEffect, useRef } from 'react';

import { useForm } from '../hooks/useForm';
import { TodoContext } from '../store/TodoContext';

export const Form: React.FC = () => {
const field = useRef<HTMLInputElement>(null);

const { query, handleAddTodo, handleChangeQuery } = useForm();
const { todos, isDeleted } = useContext(TodoContext);

useEffect(() => {
if (!field.current) {
return;
}

if (!todos.length || isDeleted) {
if (field.current) {
field.current.focus();
}
}, [todos.length, isDeleted]);
}, []);

return (
<form onSubmit={handleAddTodo}>
Expand Down

0 comments on commit 5c1961c

Please sign in to comment.