New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-ss

Package Overview
Dependencies
Maintainers
1
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-ss

A library for SSR using React 18

latest
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

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.

FAQs

Package last updated on 09 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts