RocketChat/Rocket.Chat

View on GitHub
apps/meteor/client/hooks/useExternalLink.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { useCallback } from 'react';

import { InvalidUrlError } from '../lib/errors/InvalidUrlError';

export const useExternalLink = () => {
    return useCallback((url: string | undefined) => {
        if (!url) {
            throw new InvalidUrlError();
        }
        window.open(url, '_blank', 'noopener noreferrer');
    }, []);
};