Last active
March 2, 2018 16:30
-
-
Save bruceharris/29c6afbda53bb51c9c3c7279a84a753c to your computer and use it in GitHub Desktop.
React Unit Testing Example 11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class LoadingIndicator extends Component { | |
static propTypes = { | |
isLoading: PropTypes.bool.isRequired, | |
}; | |
state = { | |
isPastDelay: false | |
}; | |
componentDidMount () { | |
this._delayTimer = setTimeout( | |
() => this.setState({ isPastDelay: true }), 200 | |
); | |
} | |
render() { | |
if (this.props.isLoading) { | |
if (!this.state.isPastDelay) { | |
return null; | |
} | |
return <div>loading...</div>; | |
} | |
return this.props.children; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment