Created
October 7, 2016 12:04
-
-
Save KATT/32a46b8483812dadacd918aea37b6199 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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