Last active
August 28, 2019 18:49
-
-
Save rgaidot/bd80b306fbee174eebe5f7432f700362 to your computer and use it in GitHub Desktop.
Text with carriage returns without dangerouslySetInnerHTML #react
This file contains 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, { Fragment } from 'react'; | |
import PropTypes from 'prop-types'; | |
const TextWithCR = ({ text }) => { | |
const lines = text.split('\n'); | |
return ( | |
<Fragment> | |
{lines.map(line => ( | |
<Fragment key={line}> | |
<p>{line}</p> | |
</Fragment> | |
)} | |
</Fragment> | |
); | |
}; | |
TextWithCR.propTypes = { | |
text: PropTypes.string.isRequired, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment