Created
March 4, 2025 11:01
-
-
Save kaineer/386a48ffe92eebf7a1d884e6653d294e to your computer and use it in GitHub Desktop.
new-task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import classes from './NewTask.module.css' | |
import { TodosSlice } from '../../slices/todo'; | |
import { useDispatch } from 'react-redux' | |
export const NewTask = ({ addTask }) => { | |
const { actions: { appendTask } } = TodosSlice; | |
const dispatch = useDispatch(); | |
const handleEnter = (e) => { | |
if (e.key === 'Enter') { | |
const taskName = e.target.value.trim(); | |
if (taskName) { | |
dispatch(appendTask(e.target.value)); | |
e.target.value = ""; | |
} | |
} | |
} | |
return ( | |
<input className={classes.input} onKeyDown={handleEnter} /> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment