import { extractString } from "@common/utils";
import { useCallback, useState } from "preact/hooks";

export const useInputState = (defaultValue = ''): [string, (e: Event | string) => void] => {
    const [value, setValue] = useState(defaultValue);

    const handleInput = useCallback((e: Event | string) => {
        setValue(extractString(e));
    }, []);

    return [value, handleInput];
}