mirror of
https://github.com/movie-web/extension.git
synced 2025-09-13 12:43:24 +00:00
20 lines
535 B
TypeScript
20 lines
535 B
TypeScript
import { useEffect, useState } from 'react';
|
|
|
|
import { makeUrlIntoDomain } from '~utils/domains';
|
|
import { listenToTabChanges, queryCurrentDomain, stopListenToTabChanges } from '~utils/tabs';
|
|
|
|
export function useDomain(): null | string {
|
|
const [domain, setDomain] = useState<string | null>(null);
|
|
|
|
useEffect(() => {
|
|
const listen = () => queryCurrentDomain(setDomain);
|
|
listen();
|
|
listenToTabChanges(listen);
|
|
return () => {
|
|
stopListenToTabChanges(listen);
|
|
};
|
|
}, []);
|
|
|
|
return makeUrlIntoDomain(domain);
|
|
}
|