init
This commit is contained in:
22
src/hooks/useInput.ts
Normal file
22
src/hooks/useInput.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { ChangeEvent, useState } from 'react';
|
||||
|
||||
/**
|
||||
* This hook allows you to handle state for inputs
|
||||
* @param {number} initialValue - initial value for useState
|
||||
* @returns {object} object that should be used for managing inputs
|
||||
*/
|
||||
const useInput = (initialValue: string) => {
|
||||
const [value, setValue] = useState(initialValue);
|
||||
|
||||
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
||||
setValue(event.target.value);
|
||||
};
|
||||
|
||||
return {
|
||||
value,
|
||||
onChange: handleChange,
|
||||
setValue,
|
||||
};
|
||||
};
|
||||
|
||||
export default useInput;
|
||||
Reference in New Issue
Block a user