React Node SSR
Overview
Simple library for rendering React components on server side in Node.js with customizable posibilities, instead of using template engines
Size: 1.9 KB
Install dependencies:
yarn add react react-dom react-node-ssr
yarn add babel-cli babel-preset-react babel-preset-env nodemon -D
Make sure you have babel configured in .babelrc:
Add a serve or start script in package.json
Basic example to follow along:
Welcome.jsx
import React from 'react'; Component { return <div> <h1>Welcome Howdy!</h1> </div> ; } ;
server.js
;;;; const app = ; app; app;
generated HTML:
Page TitleWelcome Howdy!
Docs:
title(t: string)
- Set HTML page titlelang(l: string)
- Set HTML page languagemeta(m: object)
- Set HTML page meta datascript(s: object)
- Add external script inside HTML pagelink(l: object)
- Add external link inside HTML pagestyle(s: object)
- Add inline critical style inside HTML pagerender(c: React.Component)
- React component to render in HTML template
Have fun!
Upcoming:
- Express like middleware
- More possibilities for customizing the html template
- Integrations with template engines
- Integration with webpack builds
- Possibility to import css in js or css modules or scss files directly into React components
- Redux like store for HTML template
- Add possibility to attach handlers in statically generated HTML from server using React
- Email templates crafting with the help of React