import { useCallback } from 'preact/hooks';

export const usePrompt = (
    message: string,
    defaultValue: string,
    onChange: (newValue: string) => void,
) =>
    useCallback(() => {
        const newValue = prompt(message, defaultValue);
        if (newValue?.length) {
            onChange(newValue);
        }
    }, [message, defaultValue, onChange]);
