mirror of
https://github.com/LucasVbr/todo-list.git
synced 2026-05-13 17:22:04 +00:00
33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
import {FormEvent, useState} from 'react';
|
|
import {useDispatch} from 'react-redux';
|
|
import {addTodo} from '../../features/todo/todoSlice.ts';
|
|
|
|
export default function TodoAddItemForm() {
|
|
const [name, setName] = useState('');
|
|
const dispatch = useDispatch();
|
|
|
|
const handleSubmit = (evt: FormEvent) => {
|
|
evt.preventDefault();
|
|
if (!name) return;
|
|
dispatch(addTodo(name));
|
|
setName("");
|
|
};
|
|
|
|
return (
|
|
<form onSubmit={handleSubmit} className={'TodoAddItemForm'}>
|
|
<div className={'form-control'}>
|
|
<div className={'input-group'}>
|
|
<input type={'text'} value={name} placeholder={'Type here your task...'}
|
|
className={'input input-bordered w-full'}
|
|
onChange={evt => setName(evt.target.value)}
|
|
/>
|
|
<button type={'submit'} className={'btn btn-square'}>
|
|
<img className={'h-6 w-6'} src={'/icons/plus.svg'}
|
|
alt="Plus icon"/>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
);
|
|
|
|
} |