Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { Component } from 'react';
- export default bindLoading = ({ loadingFunction }) => (Child) => {
- return class extends Component {
- constructor(props) {
- super(props);
- this.state = { loading: false };
- }
- componentDidMount() {
- const function = Child[loadingFunction];
- const isPromise = function instanceof Promise;
- if (isPromise) return function();
- this.setState({ loading: true });
- function()
- .then(() => this.setState({ loading: false }))
- .catch(() => this.setState({ loading: false }))
- }
- render() {
- const { loading } = this.state;
- return <Child loading={loading} { ...this.props} />
- }
- }
- }
Add Comment
Please, Sign In to add comment