react-render-loader
v1.2.0
Published
A webpack loader that renders React components to HTML strings.
Downloads
6
Maintainers
Readme
React render loader for webpack
A webpack loader that renders React components to HTML strings.
Warning: This loader executes your module in a Node context, use browser api will cause errors.
Usage
// App.js
import React from 'react';
function Hello(props) {
return <h1>Hello {props.name}</h1>;
}
const App = <Hello name="React" />;
export default App;
// index.js
// Use ReactDOMServer.renderToString
import AppHtml from 'react-render!./App.js';
// Use ReactDOMServer.renderToStaticMarkup
// import AppHtml from 'react-render?static=true!./App.js';
document.getElementById('root').innerHTML = AppHtml;
This loader supports
- React class
- React element
- Stateless functional components
- Array of above
- Array of above (sub arrays)
See basic example for demo.