UNPKG

evil-ui

Version:

[![npm package](https://img.shields.io/npm/v/mini-ali-ui.svg?style=flat-square)](https://www.npmjs.com/package/mini-ali-ui) [![GitHub stars](https://img.shields.io/github/stars/Alibaba-mp/mini-ali-ui.svg)](https://github.com/Alibaba-mp/mini-ali-ui/stargaz

54 lines (48 loc) 1.38 kB
import * as React from 'react' import {View, Image} from 'remax/ali' import style from './loading.less' import {from, interval, timer} from "rxjs"; export class Loading extends React.Component { constructor(props) { super(props); this.state = { isShow: false } } static defaultProps = { isShow: false, time: 300 } componentDidMount() { const delayForFiveSeconds = timer(this.props.time); delayForFiveSeconds.subscribe(res => { this.setState({ isShow: this.props.isShow }) }) } componentDidUpdate(prevProps, prevState, snapshot) { if (this.props.isShow !== prevProps.isShow) { const delayForFiveSeconds = timer(this.props.time); delayForFiveSeconds.subscribe(res => { this.setState({ isShow: this.props.isShow }) }) } } render() { const {isShow} = this.state return ( <View className={style.box}> {isShow && <View className={style.loadBox}> <Image className={style.loadImg} src={'./loading.gif'}/> </View> }{!isShow && this.props.children } </View> ) } }