plurall-wait

2.0.35 • Public • Published

PlurallWait

This component encapsulates the asynchronous rendering logic present in many of our applications.

It receives a promise and render a loading animation until the promise is resolved. Then it renders the children (as a function).

How to use

You can use it with a promise:

class MyComponent extends React.Component {
  componentDidMount() {
    const requestPromise = fetch('http://qualquercoisa.com')
    this.setState({ requestPromise })
  }

  render() {
    return (
      <Wait payload={this.requestPromise}>
        {data => <div>{data}</div>}
      </Wait>
    )
  }
}

Or with a plain object:

class MyComponent extends React.Component {
  componentDidMount() {
    fetch('http://qualquercoisa.com').then(data => {
      this.setState({ data })
    })
  }

  render() {
    return (
      <Wait payload={this.state.data}>
        {data => <div>{data}</div>}
      </Wait>
    )
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i plurall-wait

Weekly Downloads

7

Version

2.0.35

License

MIT

Unpacked Size

11.9 kB

Total Files

9

Last publish

Collaborators

  • plurall-dev