react-ss
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

React SSR

A library for SSR using React 18

Installation

# Using NPM
npm i react-ss

# Using yarn
yarn add react-ss

Make sure you have React and React DOM installed.

Example usage

import ssr from "react-ss";
import express from "express";

// Create the root to render
// Use this with nodemon to rebuild when anything change
await ssr.build();

// Create an express server
const app = express();

// Serve the hydrate file
app.use(express.static(".root"));

// Render the homepage on every request ("./pages/home.js")
app.use(async (req, res) => {
    const content = await ssr.renderToHTML("/home");
    res.end(content);
});

// Start the server
app.listen(8080);

Documentation

  • build(): Promise<void>: Generate a .root directory. renderToHTML can't work before calling this.
  • renderToHTML(): Promise<string>: Render a page to HTML string. You need to serve the .root directory as a static for this to work.

Readme

Keywords

none

Package Sidebar

Install

npm i react-ss

Weekly Downloads

4

Version

1.0.2

License

MIT

Unpacked Size

13.1 kB

Total Files

18

Last publish

Collaborators

  • reve-node