Skip to content

Commit

Permalink
Make test pass – render loading indicator when delay has elapsed
Browse files Browse the repository at this point in the history
  • Loading branch information
bruceharris committed Dec 6, 2017
1 parent 706f34f commit 8a75ba5
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/components/LoadingIndicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,22 @@ export default class LoadingIndicator extends Component {
isLoading: PropTypes.bool.isRequired,
};

state = {
isPastDelay: false
};

componentWillMount () {
this._delayTimer = setTimeout(
() => this.setState({ isPastDelay: true }), 200
)
}

render() {
if (this.props.isLoading) {
return null;
if (!this.state.isPastDelay) {
return null;
}
return <div>loading...</div>;
}
return this.props.children;
}
Expand Down

0 comments on commit 8a75ba5

Please sign in to comment.