Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

boundless-async

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

boundless-async

A higher-order component for rendering data that isn't ready yet.

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Async

A higher-order component for rendering data that isn't ready yet.

There are plenty of situations where you need to fetch content to be displayed, but want to show some sort of loading graphic in the interim. This component helps to simplify that pattern by handling common types of promises and providing a simple mechanism for materializing the fulfilled payload into JSX.

Props

Note: only top-level props are in the README, for the full list check out the website.

Required Props

  • children ・ a promise, function that returns a promise, or other type of renderable content; if a function is passed, it will be called with the current props

    Promise example:

    const listDataPromise = fetch('/some/list/data/endpoint').then(
        (response) => response.ok ? response.json() : 'Failed to receive list data',
        (error) => error.message,
    ).then((payload) => {
        if (typeof payload === 'string') {
            return (<div className='error'>{payload}</div>);
        }
    
        return (
            <ul>
                {payload.map((item) => (<li key={item.id}>{item.content}</li>))}
            </ul>
        );
    });
    

    {listDataPromise}

    Function example:

    const fetchListData = (props) => fetch(props['data-endpoint']).then(
        (response) => response.ok ? response.json() : 'Failed to receive list data',
        (error) => error.message,
    ).then((payload) => {
        if (typeof payload === 'string') {
            return (<div className='error'>{payload}</div>);
        }
    
        return (
            <ul>
                {payload.map((item) => (<li key={item.id}>{item.content}</li>))}
            </ul>
        );
    });
    
    <Async data-endpoint='/some/list/data/endpoint'>{fetchListData}</Async>
    

    Expects | Default Value

    •   | -
      

    function or any renderable or Promise | <div />

Optional Props

  • * ・ any React-supported attribute

    Expects | Default Value

    •   | -
      

    any | n/a

  • childrenDidRender ・ a callback for when real content has been rendered; this will be called immediately if normal JSX is passed to Async, or, in the case of a promise, upon resolution or rejection

    Expects | Default Value

    •   | -
      

    function | () => {}

  • pendingContent ・ content to be shown while the promise is in "pending" state (like a loading graphic, perhaps)

    Expects | Default Value

    •   | -
      

    any renderable | <div />

Reference Styles

Stylus

// Bring in Boundless's base Stylus variables
@require "node_modules/boundless-async/variables"

// Redefine any variables as desired, e.g.
color-accent = royalblue

// Bring in the component styles; they will be autoconfigured based on the above
@require "node_modules/boundless-async/style"

CSS

If desired, a precompiled plain CSS stylesheet is available for customization at /build/style.css, based on Boundless's default variables.

Keywords

FAQs

Package last updated on 09 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc