Socket
Socket
Sign inDemoInstall

react-server-dom-webpack

Package Overview
Dependencies
Maintainers
5
Versions
1215
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-server-dom-webpack

React Server Components bindings for DOM using Webpack. This is intended to be integrated into meta-frameworks. It is not intended to be imported directly.


Version published
Weekly downloads
184K
decreased by-12.08%
Maintainers
5
Weekly downloads
 
Created

Package description

What is react-server-dom-webpack?

The react-server-dom-webpack package is designed to enable Server-Driven Rendering (SDR) with React. It allows you to render React components on the server and send them to the client as a stream, which can then be hydrated on the client side. This approach can improve performance and user experience by allowing the server to handle the initial rendering and the client to take over once the initial HTML is loaded.

What are react-server-dom-webpack's main functionalities?

Server-Side Rendering

This feature allows you to render React components on the server side. The code sample demonstrates how to use ReactDOMServer to render a React component to a string.

const React = require('react');
const ReactDOMServer = require('react-dom/server');
const App = require('./App');

const serverRender = () => {
  return ReactDOMServer.renderToString(<App />);
};

console.log(serverRender());

Streaming HTML to Client

This feature allows you to stream HTML content to the client. The code sample demonstrates how to use ReactDOMServer's renderToNodeStream method to stream a React component to the client using an Express server.

const React = require('react');
const ReactDOMServer = require('react-dom/server');
const App = require('./App');
const express = require('express');
const app = express();

app.get('/', (req, res) => {
  const stream = ReactDOMServer.renderToNodeStream(<App />);
  res.type('html');
  stream.pipe(res);
});

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

Hydration on Client Side

This feature allows the client to take over the server-rendered HTML and make it interactive. The code sample demonstrates how to use the hydrateRoot method from react-dom/client to hydrate a React component on the client side.

import React from 'react';
import { hydrateRoot } from 'react-dom/client';
import App from './App';

hydrateRoot(document.getElementById('root'), <App />);

Other packages similar to react-server-dom-webpack

Readme

Source

react-server-dom-webpack

Experimental React Flight bindings for DOM using Webpack.

Use it at your own risk.

Keywords

FAQs

Package last updated on 10 Jun 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc