npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-iframe-helper

v1.4.1

Published

This is a react library meant to simplify the usage of `iframe` component in react web apps with following features: - Manage the loading status of the `iframe` content. - Simplify the communication between the parent web app and the inner app.

Downloads

21

Readme

This is a react library meant to simplify the usage of iframe component in react web apps with following features:

  • Manage the loading status of the iframe content.
  • Simplify the communication between the parent web app and the inner app.

Besides these two main features efforts have also been made to guaranteed security by checking the source origin of the messages.

Another thing worth mentioning for folks using typescript is that the whole lib is written in ts so types will never be a concern.

What's Under the hood

The idea is very simple. To tell if the app inside the iframe is running properly, just send a query mesage to query the status.

Once it replies then we know is's working.

If we wait for a certain amount of time without receiving the reply we see it as a loading failure.

Quick Start

Installation is fairly easy: npm install react-iframe-helper.

To use This Lib At the parent App

we will invoke the hook firstly.

const { ref, status, onLoad, send } = useIFrameParent({
                                        delay: 50 //default to 500,
                                        childDomain:'http://localhost:3006', //required
                                        listen: listenerCallback,  //optional
                                        count:10  //deafult to 10
                                        })

The count arg is about how many times we will try the status query and the delay arg is the interval in which we will send the query. For example, With the above shown code the status would be marked as failed when we wait for 500ms without receiving the reply.

Apart from that the childDomain arg is the domain of the inner app for security check.

Lastly the listen arg is used as a callback to handle the message from the inner app.

Having the useIFrameParent invoked, the remaining work is just set the ref and onLoad(returned from the useIFrameParent hook) properly for the iframe component.

<iframe
    ref={ref}
    onLoad={onLoad}
    title='forms'
    src={'http://localhost:3006'}
/>

Now in the parent app, we can check if status is equal to IFrameStatus.LOADING, IFrameStatus.LOADED or IFRameStatus.FAILED to see the status of the inner app and and send messages to the inner app with send returned from the IFrameParent hook.

To use This Lib At the inner App

Similiar to how we use the useIFrameParent hook, we send the parent domain and a listener: const { send } = useIFrameChild({parentDomain: 'http://localhost:3000', listen }).

Then messages from the parent app can be retrieved through the listen we send in and to send messages to parent app, just use the send method returned.