Skip to content

Instantly share code, notes, and snippets.

@moodysalem
Created November 11, 2016 19:18
Show Gist options
  • Save moodysalem/05c1c96451dea86a4f46827cca031c4f to your computer and use it in GitHub Desktop.
Save moodysalem/05c1c96451dea86a4f46827cca031c4f to your computer and use it in GitHub Desktop.
Render React component to text
import { render, unmountComponentAtNode } from 'react-dom';
export function renderText(component) {
const _el = document.createElement('div');
document.body.appendChild(_el);
render(component, _el);
const text = _el.innerText;
unmountComponentAtNode(_el);
document.body.removeChild(_el);
return text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment