react-render-loader

1.2.0 • Public • Published

npm version

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.

Package Sidebar

Install

npm i react-render-loader

Weekly Downloads

2

Version

1.2.0

License

MIT

Last publish

Collaborators

  • jas-chen