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-faux-suspense

v1.0.4

Published

Experiment in loading methodology.

Downloads

6

Readme

React Faux Suspense

An experiment in loading-UX.

Inspiration

This is a simple experiment in the upcoming React Suspense UX model, which should land with React v17. The geist of the feature (really, one facet thereof) is that loading data into an application is an unpredictable process. All manner of network and processing delays mean that a dev can't be certain of when requested data will show up for presentation.

The default solution is to render a loading spinner until the requisite data for a view has arrived. While effective, this solution is less than ideal under more ideal circumstances (i.e. when the data loads quickly -- thank heaven). Loading spinners flash in and out, and interfaces quickly become cluttered as a result. Thus, Suspense is, in part, aimed to standardize the intermediate loading state.

Rather than simply showing a loading spinner until the data is ready, Suspense will make it straightforward to, in effect, render nothing at first from a view which requires data (but has yet to receive it). The implication is that, if you envision an entire tree of React components, an entire branch can render without waiting for a "leaf" to get its data. Andrew Clark describes it in more detail and gives us the "Count the Placeholders" game (see 5m:30s of the video).

Suspense addresses the problem Andrew highlighted (and many others!) by enabling developers to specify an interval after which and only after which, if the data has still not arrived, the spinner is finally displayed.

This Library

This library is just a crude mock of this functionality. It provides a component FauxSuspense which takes a prop timeout (duration in ms) and a "children function" and provides a render-prop object with a timerExpired property. timerExpired can be used to only display content (e.g. loading spinner) after the specified delay.

Example Usage

I generally use this component alongside a data loading component, ergo I commonly have a loading property available. Used in tandem with FauxSuspense, I imitate the upcoming feature release.

import FauxSuspense from 'react-faux-suspense'

...

render () {
    let loading = ...

    <FauxSuspense timeout={500}>
        {
            ({timerExpired}) => {
                if(loading && timerExpired) return <Spinner/>
                if(loading && !timerExpired) return null
                return <ContentWithData/>
            }
        }
    </FauxSuspense>
}