import React, { useEffect } from "react";
import { useParentFrame } from "./useFrame";
/**
 * Component connecting to the host of the frame.
 * Once the connection has been established, `onConnected` will be called and will provide, as first parameter, a function to send actions to the host.
 * This component must be provided a `dispatch `function that will listen for actions coming from the host.
 */
export var HostConnector = function (_a) {
    var dispatch = _a.dispatch, children = _a.children, onConnected = _a.onConnected;
    var _b = useParentFrame({
        dispatch: dispatch,
    }), connected = _b[0], toHost = _b[1];
    useEffect(function () {
        if (connected) {
            onConnected(function (action) {
                if (toHost.dispatch) {
                    toHost.dispatch(action);
                }
            });
        }
    }, [connected, toHost, onConnected]);
    return React.createElement(React.Fragment, null, children);
};
//# sourceMappingURL=HostConnector.js.map