import * as React from 'react';
export function requestActionPostMessage(action, data, destinationElement) {
    const message = { action, data };
    destinationElement.postMessage(message);
}
export function listenPostMessageEvents(action, callback) {
    const onMessage = (e) => {
        const message = e.data;
        if ('action' in message && message.action === action) {
            return callback(message.data);
        }
        return undefined;
    };
    window.addEventListener('message', onMessage);
    return () => {
        window.removeEventListener('message', onMessage);
    };
}
export function usePostMessageAPIListener(action, callback, deps = []) {
    React.useEffect(() => {
        return listenPostMessageEvents(action, callback);
        // eslint-disable-next-line react-hooks/exhaustive-deps
    }, [...deps]);
}
//# sourceMappingURL=postMessage.js.map
