Skip to content

Instantly share code, notes, and snippets.

@rgaidot
Last active August 28, 2019 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgaidot/bd80b306fbee174eebe5f7432f700362 to your computer and use it in GitHub Desktop.
Save rgaidot/bd80b306fbee174eebe5f7432f700362 to your computer and use it in GitHub Desktop.
Text with carriage returns without dangerouslySetInnerHTML #react
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