react-with-spinner
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

react-with-spinner

Build Status npm version License

React HOC for displaying a Spinner component while loading.

Install

yarn add react-with-spinner
npm install --save react-with-spinner

Usage

By default withSpinner will look for the property data and if that property contains an loading property that is true then it will render a Spinner.

import compose from 'recompose/compose'
import {withSpinner} from 'react-with-spinner'
 
const Component = compose(
  WrappedComponent => props => <WrappedComponent {...props} data={{loading: true}} />,
  withSpinner(),
)(() => <div></div>)
 

You can override which property withSpinner should look for:

import compose from 'recompose/compose'
import {withSpinner} from 'react-with-spinner'
 
const Component = compose(
  WrappedComponent => props => <WrappedComponent {...props} result={{loading: true}} />,
  withSpinner({prop: 'result'}),
)(() => <div></div>)
 

The spinnerComponent defaults to a React Toolbox ProgressBar component. However, it is possible to provide your own component:

import compose from 'recompose/compose'
import {withSpinner} from 'react-with-spinner'
 
const Loading = () => <span>Loading...</span>
 
const Component = compose(
  WrappedComponent => props => <WrappedComponent {...props} data={{loading: true}} />,
  withSpinner({spinnerComponent: Loading}),
)(() => <div></div>)
 

For more usages, check out the tests

License

react-with-spinner is dual-licensed under Apache 2.0 and MIT terms.

Readme

Keywords

none

Package Sidebar

Install

npm i react-with-spinner

Weekly Downloads

12

Version

1.0.0

License

MIT

Unpacked Size

99.7 kB

Total Files

22

Last publish

Collaborators

  • beanloop
  • drager