import { useCallback } from "preact/hooks";

export function useInputCallback<T>(callback: (value: string) => T, deps: any[]): ((value: string | Event) => T) {
    return useCallback((e: Event | string) => {
        if (typeof e === 'string') {
            return callback(e);
        } else {
            const { target } = e;
            if (target && 'value' in target && typeof target.value === 'string') {
                return callback(target.value);
            }
        }

        return callback('');
    }, deps);
}