Skip to content

Commit

Permalink
Remove usePopupReady arg
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonMHasperhoven committed Aug 28, 2024
1 parent 3cba6f5 commit a9d0478
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions apps/extension/src/hooks/popup-ready.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { useEffect, useRef } from 'react';
import { useSearchParams } from 'react-router-dom';

type IsReady = boolean | undefined;

// signals that react is ready (mounted) to service worker
export const usePopupReady = (isReady: IsReady = undefined) => {
export const usePopupReady = () => {
const sentMessagesRef = useRef(new Set());
const [searchParams] = useSearchParams();
const popupId = searchParams.get('popupId');

useEffect(() => {
if (popupId && (isReady === undefined || isReady) && !sentMessagesRef.current.has(popupId)) {
if (popupId && !sentMessagesRef.current.has(popupId)) {
sentMessagesRef.current.add(popupId);

void chrome.runtime.sendMessage(popupId);
}
}, [popupId, isReady]);
}, [popupId]);
};

0 comments on commit a9d0478

Please sign in to comment.