Convert vscodeMessageHandler to use useCallback

This commit is contained in:
Robert
2023-08-11 17:22:21 +01:00
parent da8f959c42
commit d173ff3c48

View File

@@ -145,13 +145,16 @@ export function ResultTables(props: ResultTablesProps) {
} }
}, []); }, []);
const vscodeMessageHandler = (evt: MessageEvent): void => { const vscodeMessageHandler = useCallback(
// sanitize origin (evt: MessageEvent): void => {
const origin = evt.origin.replace(/\n|\r/g, ""); // sanitize origin
evt.origin === window.origin const origin = evt.origin.replace(/\n|\r/g, "");
? handleMessage(evt.data as IntoResultsViewMsg) evt.origin === window.origin
: console.error(`Invalid event origin ${origin}`); ? handleMessage(evt.data as IntoResultsViewMsg)
}; : console.error(`Invalid event origin ${origin}`);
},
[handleMessage],
);
// TODO: Duplicated from results.tsx consider a way to // TODO: Duplicated from results.tsx consider a way to
// avoid this duplication // avoid this duplication