insomnia/app/ui/components/GravatarImg.js
Gregory Schier b198e6170b React performance sweep (#96)
* Removed some unnecessary rendering

* Only PureComponents and some other stuff

* Removed all functional components

* Only deal with nunjucks marks

* Remove ref assign functions in modals

* Lots of tweaks

* A bit snappier

* A bit snappier
2017-02-28 13:32:23 -08:00

30 lines
775 B
JavaScript

import React, {PureComponent, PropTypes} from 'react';
import crypto from 'crypto';
class GravatarImg extends PureComponent {
render () {
const {email, size, className} = this.props;
const sanitizedEmail = email.trim().toLowerCase();
const hash = crypto
.createHash('md5')
.update(sanitizedEmail)
.digest('hex');
const url = `https://www.gravatar.com/avatar/${hash}?s=${size * 2}`;
const cssSize = `${size}px`;
return (
<img src={url}
alt="Profile picture"
className={className}
title={sanitizedEmail}
style={{width: cssSize, height: cssSize}}/>
)
}
}
GravatarImg.propTypes = {
email: PropTypes.string.isRequired,
size: PropTypes.number
};
export default GravatarImg;