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 => {
// sanitize origin
const origin = evt.origin.replace(/\n|\r/g, "");
evt.origin === window.origin
? handleMessage(evt.data as IntoResultsViewMsg)
: console.error(`Invalid event origin ${origin}`);
};
const vscodeMessageHandler = useCallback(
(evt: MessageEvent): void => {
// sanitize origin
const origin = evt.origin.replace(/\n|\r/g, "");
evt.origin === window.origin
? handleMessage(evt.data as IntoResultsViewMsg)
: console.error(`Invalid event origin ${origin}`);
},
[handleMessage],
);
// TODO: Duplicated from results.tsx consider a way to
// avoid this duplication