Created
November 11, 2016 19:18
-
-
Save moodysalem/05c1c96451dea86a4f46827cca031c4f to your computer and use it in GitHub Desktop.
Render React component to text
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 { 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