insomnia/app/ui/components/Nl2Br.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

25 lines
558 B
JavaScript

import React, {PureComponent, PropTypes} from 'react';
class Nl2Br extends PureComponent {
render () {
const {children, ...props} = this.props;
const text = children || '';
const lines = text.trim().split('\n');
return (
<p {...props}>{lines.map((l, i) => {
const trimmed = l.trim();
if (trimmed) {
const brs = i < lines.length - 1 ? [<br/>] : [];
return [trimmed, ...brs];
} else {
return null;
}
})}</p>
);
}
}
Nl2Br.propTypes = {};
export default Nl2Br;