Skip to content

Instantly share code, notes, and snippets.

@kaineer
Created March 4, 2025 11:01
Show Gist options
  • Save kaineer/386a48ffe92eebf7a1d884e6653d294e to your computer and use it in GitHub Desktop.
Save kaineer/386a48ffe92eebf7a1d884e6653d294e to your computer and use it in GitHub Desktop.
new-task
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