Skip to content

Instantly share code, notes, and snippets.

@bruceharris
Last active March 2, 2018 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bruceharris/29c6afbda53bb51c9c3c7279a84a753c to your computer and use it in GitHub Desktop.
Save bruceharris/29c6afbda53bb51c9c3c7279a84a753c to your computer and use it in GitHub Desktop.
React Unit Testing Example 11
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