Skip to content

Commit

Permalink
Feat: useInput 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
navyjeongs committed Jan 18, 2024
1 parent 1f721c5 commit 3b8c538
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/hooks/useInput.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useState, useCallback } from 'react';

const useInput = (initialValue: string) => {
const [inputValue, setInputValue] = useState<string>(initialValue);

const handleValue = useCallback(
(e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
const { value } = e.target;

setInputValue(value);
},
[],
);

const resetValue = useCallback(() => {
setInputValue('');
}, []);

return [inputValue, handleValue, resetValue] as const;
};

export default useInput;

0 comments on commit 3b8c538

Please sign in to comment.