react-iframe

  • Version 2.0.1
  • Published
  • 61.6 kB
  • No dependencies
  • ISC license

Install

npm i react-iframe
yarn add react-iframe
pnpm add react-iframe

Overview

A zero-dependency, typed, ref-forwarding iframe component for React 18+

Index

Variables

variable Iframe

const Iframe: react.ForwardRefExoticComponent<any>;

    Functions

    function postToIframe

    postToIframe: (
    iframe: HTMLIFrameElement | null | undefined,
    message: unknown,
    targetOrigin: string
    ) => boolean;
    • Post a message to an iframe's contentWindow. Returns false when the iframe is missing or not yet ready.

      targetOrigin is required. Use the child's origin. For a srcDoc frame the origin is opaque and the browser rejects "null" — pass "*".

    function useIframeMessage

    useIframeMessage: (
    handler: (event: MessageEvent) => void,
    options?: UseIframeMessageOptions
    ) => void;
    • Subscribe to window "message" events from framed documents. Pair with postToIframe or ref.current.contentWindow.postMessage.

    Type Aliases

    type IframeMessageSource

    type IframeMessageSource =
    | Window
    | HTMLIFrameElement
    | RefObject<HTMLIFrameElement | null | undefined>;

      type IframeProps

      type IframeProps = NativeIframeProps &
      Conveniences &
      (WithUrl | WithSrc | WithSrcDoc);

        type SandboxToken

        type SandboxToken =
        | 'allow-downloads'
        | 'allow-downloads-without-user-activation'
        | 'allow-forms'
        | 'allow-modals'
        | 'allow-orientation-lock'
        | 'allow-pointer-lock'
        | 'allow-popups'
        | 'allow-popups-to-escape-sandbox'
        | 'allow-presentation'
        | 'allow-same-origin'
        | 'allow-scripts'
        | 'allow-storage-access-by-user-activation'
        | 'allow-top-navigation'
        | 'allow-top-navigation-by-user-activation'
        | 'allow-top-navigation-to-custom-protocols';

          type SandboxValue

          type SandboxValue = SandboxToken | (string & {});

            type UseIframeMessageOptions

            type UseIframeMessageOptions = {
            /**
            * When set, messages from other origins are ignored.
            * A `srcDoc` frame has origin `"null"` (the string).
            */
            origin?: string;
            /**
            * When set, messages whose `event.source` is not this frame's
            * `contentWindow` are ignored. Prefer this over origin-only filtering
            * when several frames share an origin.
            */
            source?: IframeMessageSource | null;
            };

              Package Files (1)

              Dependencies (0)

              No dependencies.

              Dev Dependencies (18)

              Peer Dependencies (2)

              Badge

              To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

              You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/react-iframe.

              • Markdown
                [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/react-iframe)
              • HTML
                <a href="https://www.jsdocs.io/package/react-iframe"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>