import { useMemo, useState } from "react"; import { SelectOption } from "../shared/types"; import { getCreatableOption } from "../shared/utils"; interface UseSelectCreatableProps { inputValue?: string; onCreateOption?: (newOption: string) => void; } export function useSelectCreatable({ inputValue, onCreateOption, }: UseSelectCreatableProps) { const isCreatable = !!onCreateOption && !!inputValue; const creatableOption = useMemo(() => { return getCreatableOption(inputValue); }, [inputValue]); const [inputHasFocus, setInputHasFocus] = useState(false); return { isCreatable, creatableOption, inputHasFocus, setInputHasFocus }; }