Skip to content

Instantly share code, notes, and snippets.

@rgaidot

rgaidot/TextWithCR.js

Last active Aug 28, 2019
Embed
What would you like to do?
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
You can’t perform that action at this time.