import React from 'react'; interface Props { text: string; } export class AddNewLines extends React.Component { public render() { const { text } = this.props; const results: Array = []; const FIND_NEWLINES = /\n/g; let match = FIND_NEWLINES.exec(text); let last = 0; let count = 1; if (!match) { return {text}; } while (match) { if (last < match.index) { const textWithNoNewline = text.slice(last, match.index); results.push({textWithNoNewline}); } results.push(
); // @ts-ignore last = FIND_NEWLINES.lastIndex; match = FIND_NEWLINES.exec(text); } if (last < text.length) { results.push({text.slice(last)}); } return {results}; } }