import { useCallback, useState, Dispatch, SetStateAction } from 'react' export default function useSubmittableTextInput( handleSubmit: ( content: string, setContent: Dispatch> ) => void ) { const [content, setContent] = useState('') const handleKeyPress = useCallback( (e: React.KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey && !e.ctrlKey && !e.metaKey) { e.preventDefault() handleSubmit(content, setContent) } }, [content, handleSubmit] ) const handleChange = useCallback( (e: React.ChangeEvent) => { setContent(e.target.value) }, [] ) return { handleChange, handleKeyPress, content } }