/* eslint-disable react/prop-types */ import React from 'react'; import Loader from 'components/loader/loader.jsx'; import Button from './button.jsx'; import './buttons.scss'; export default class ButtonWithTimeout extends React.Component { /* props = { loading : boolean value : text in button loadingTimeout : time before show loading disabled onClick style className } */ constructor() { super(); this.state = { showLoader: false, }; this.timeout = ''; } componentWillUnmount() { clearTimeout(this.timeout); } componentDidUpdate(prevProps) { // eslint-disable-next-line @typescript-eslint/no-this-alias var that = this; if (prevProps.loading && !this.props.loading) { if (this.state.showLoader) { this.setState({ showLoader: false }); } clearTimeout(this.timeout); } else if (!prevProps.loading && this.props.loading) { this.timeout = setTimeout(function () { that.setState({ showLoader: true }); }, this.props.loadingTimeout || 2000); } } render() { return (
{this.state.showLoader && }
); } }