Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@abhishekjakhar
Created April 30, 2019 15:31
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 abhishekjakhar/bc13b81a9b2c54362938f93f7c533c97 to your computer and use it in GitHub Desktop.
Save abhishekjakhar/bc13b81a9b2c54362938f93f7c533c97 to your computer and use it in GitHub Desktop.
Mocktail Component
import React, { Component } from 'react';
import Spinner from './Spinner';
class Mocktail extends Component {
state = {
isLoading: false
}
componentWillReceiveProps() {
this.setState({ isLoading: true });
setTimeout(() =>
this.setState({
isLoading: false
}), 500);
}
render() {
if (this.state.isLoading) {
return <Spinner/>
}
return (
<React.Fragment>
<div className="mocktail-image">
<img src={`img/${this.props.mocktail.replace(/ +/g, "").toLowerCase()}.png`} alt={this.props.mocktail} />
</div>
</React.Fragment>
);
}
}
export default Mocktail;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment