1.2.3 • Published 4 years ago

react-with-loading-srian v1.2.3

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

react-with-loading

react-with-loading-srian is a react HOC that shows your data after it's been fetched, a loader when it's loading, and an error if it fails.

Build Status semantic-release Coverage Status

Install

npm i react-with-loading-srian

Quick Start Example

Write your view as normal
const View = ({ id, title, completed }) => (
  <div>
    <div>ID: {id}</div>
    <div>Title: {title}</div>
    <div>Completed? {completed ? 'Yes' : 'No'}</div>
  </div>
);
Wrap it in withLoading
const ViewWithLoading = withLoading(View);
Use the Wrapped component and pass it a loading prop
<ViewWithLoading loading={!state} {...state} />

Basic Example

Edit with-loading-basic

Advanced Use Example

Edit with-react-loading-advanced-usage

PropTypes

withLoading.propTypes = {
  Component: PropTypes.element,
  FallbackOptions: PropTypes.shape({  // FallbackOptions allows you to write your own HOC with your own default Fallbacks
    LoadingFallback: PropTypes.func,
    ErrorFallback: PropTypes.func,
  }),
};
Wrapped.propTypes = {
  loading: PropTypes.bool.isRequired,
  error: PropTypes.any,
  LoadingFallback: PropTypes.func,
  ErrorFallback: PropTypes.func,
};
1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago