Is it valid to place a hook inside and call it from within there?

VSCode doesn’t mark this as invalid, despite the hooks being conditionally run:

function useHook() {
    return 1;
}
function useHook2() {
    const two = useMemo(() => 2, []);
    return two;
}

const hookDictionary = {
    useHook,
    useHook2
}

export function HookUser(index) { 
    let func = hookDictionary[index];
    func();
    return null;
}

Is this intentional, and considered valid?
Is it being hidden by the use of hookDictionary?
My assumption is that this is the case, since it’s functionally the same as:

export function HookUser(index: string) { 
    let func = hookDictionary[index];
    if(index === 'useHook') {
        useHook();
    }
    else if(index === 'useHook2') {
        useHook2();
    }
    return null;
}

Which does throw an error.