@ovotech/async-reactor-ts
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

async-reactor-ts

Render async Stateless Functional Components, using Typescript

Installation

yarn add async-reactor-ts

It has peer dependencies of "react" and "react-dom"

Usage

import * as React from 'react';
import { AsyncReactor } from '@ovotech/async-reactor-ts';

const Home = (
  <AsyncReactor loader={() => someAsnycStuff()}>
    {({ loading, result }) => {
      if (loading) {
        return <div>Loading</div>;
      }

      return <div>Home Screen {result}</div>;
    }}
  </AsyncReactor>
);

You'll receive the result of the async loader call in the "result" prop

Handle errors

If there is an error in the loader, you will receive it as an "error" prop

import * as React from 'react';
import { AsyncReactor } from '@ovotech/async-reactor-ts';

const Home = (
  <AsyncReactor loader={() => someAsnycStuff()}>
    {({ loading, error }) => {
      if (loading) {
        return <div>Loading</div>;
      }

      if (error) {
        return <div>Error {error.message}</div>;
      }

      return <div>Home Screen</div>;
    }}
  </AsyncReactor>
);

Example using fetch

import * as React from 'react';
import { AsyncReactor } from '@ovotech/async-reactor-ts';

const Home = (
  <AsyncReactor
    loader={async () => {
      const data = await fetch('https://jsonplaceholder.typicode.com/posts');
      return await data.json();
    }}
  >
    {({ loading, result }) => {
      if (loading) {
        return <div>Loading</div>;
      }

      return <ul>{result.map(x => <li key={x.id}>{x.title}</li>)}</ul>;
    }}
  </AsyncReactor>
);

Development

In order to develop on this package:

git clone git@github.com:ovotech/async-reactor-ts.git
cd async-reactor-ts
yarn

Running tests

yarn lint
yarn test

Deploying new versions

New versions are deployed using "Github Releases" feature. We use SemVer for versioning. For the versions available, see npm async-reactor-ts.

Authors

  • Ivan Kerin - Initial work - ivank

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

Inspired by async-reactor project

Readme

Keywords

none

Package Sidebar

Install

npm i @ovotech/async-reactor-ts

Weekly Downloads

1

Version

0.2.0

License

MIT

Unpacked Size

11.6 kB

Total Files

17

Last publish

Collaborators

  • ovox
  • oep-accounts-bot
  • ovo.backstage.admins
  • bookings-team
  • orion-bot
  • bizval-bot
  • oeptariffs
  • props
  • metering-reads-health-bot
  • ovotech-identity
  • paceteamkaluza
  • trading-and-dispatch
  • retail-payg-tech
  • accrecovo
  • ovo.trading.tech
  • qe-team
  • ovotech-smart-thermostat
  • rise-team
  • engagement-insights
  • myovo-self-serve-service-account
  • mars-rover
  • ape-team
  • kaluza-devex
  • ohs-aurora
  • kaluza-rnr
  • ipa-bot
  • kawbot
  • data.discovery.ovo
  • ovotech-sg
  • ovotech-qs
  • ovoenergyapps
  • homemoves
  • ovo-oot-bot
  • cp-ui-tooling
  • ovo-bit-tech
  • sir_hiss