Skip to content

Instantly share code, notes, and snippets.

@KATT
Created October 7, 2016 12:04
Show Gist options
  • Save KATT/32a46b8483812dadacd918aea37b6199 to your computer and use it in GitHub Desktop.
Save KATT/32a46b8483812dadacd918aea37b6199 to your computer and use it in GitHub Desktop.
import React, { PropTypes } from 'react';
function NL2BR({content}) {
const strs = content.split('\n');
const {length} = strs;
if (length === 1) {
return <span>{content}</span>;
}
return (
<div>
{strs.map((str, i) =>
<span key={i}>
{str}
{i !== length-1 && <br/>}
</span>
)}
</div>
);
}
NL2BR.propTypes = {
content: PropTypes.string.isRequired,
};
export default NL2BR;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment