Skip to content

ThaddeusJiang/react-promise-data

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Welcome to @thaddeusjiang/react-promise-data πŸ‘‹

Version Documentation Maintenance License: MIT Twitter: ThaddeusJiang

Don't wrong again about "isLoading? πŸ”„ : isError ? ❌ : πŸ‘"

Features

  • isLoading? πŸ”„ : isError ? ❌ : πŸ‘

Install

yarn add @thaddeusjiang/react-promise-data

Usage

export const DefaultLoading = () => {
  return (
    <PromiseDataRender isLoading={true} isError={false} data={'anything'}>
      {({ data }) => <div>{data}</div>}
    </PromiseDataRender>
  );
};

export const DefaultError = () => {
  return (
    <PromiseDataRender isLoading={false} isError={true} data={'anything'}>
      {({ data }) => <div>{data}</div>}
    </PromiseDataRender>
  );
};

export const DefaultData = () => {
  return (
    <PromiseDataRender isLoading={false} isError={false} data={'anything'}>
      {({ data }) => <div>{data}</div>}
    </PromiseDataRender>
  );
};

export const CustomLoading = () => {
  return (
    <PromiseDataRender
      isLoading={true}
      isError={false}
      data={'anything'}
      loadingComponent={() => <div>πŸ”„ Custom Loading...</div>}
    >
      {({ data }) => <div>{data}</div>}
    </PromiseDataRender>
  );
};

export const CustomError = () => {
  return (
    <PromiseDataRender
      isLoading={false}
      isError={true}
      data={'anything'}
      error={new Error('πŸ’₯ Custom Error!')}
      errorComponent={(error) => <div>πŸ’₯ Custom Error: {error}</div>}
    >
      {({ data }) => <div>{data}</div>}
    </PromiseDataRender>
  );
};

Development

Storybook

Run inside another terminal:

yarn storybook

Example

Then run the example inside another:

yarn link

cd example
yarn link "@thaddeusjiang/react-promise-data"
yarn # or yarn to install dependencies
yarn start #

Run tests

yarn test

Author

πŸ‘€ Thaddeus Jiang

🀝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page. You can also take a look at the contributing guide.

Show your support

Give a ⭐️ if this project helped you!

πŸ“ License

Copyright Β© 2022 Thaddeus Jiang.
This project is MIT licensed.


This README was generated with ❀️ by readme-md-generator

About

Don't wrong again about "isLoading? πŸ”„ : isError ? ❌ : πŸ‘"

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published