mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
Stacked on #33150. We use `noop` functions in a lot of places as place holders. I don't think there's any real optimizations we get from having separate instances. This moves them to use a common instance in `shared/noop`. |
||
|---|---|---|
| .. | ||
| npm | ||
| src | ||
| client.js | ||
| index.js | ||
| package.json | ||
| profiling.js | ||
| README.md | ||
| server.browser.js | ||
| server.bun.js | ||
| server.edge.js | ||
| server.js | ||
| server.node.js | ||
| static.browser.js | ||
| static.edge.js | ||
| static.js | ||
| static.node.js | ||
| test-utils.js | ||
| unstable_server-external-runtime.js | ||
| unstable_testing.experimental.js | ||
| unstable_testing.js | ||
react-dom
This package serves as the entry point to the DOM and server renderers for React. It is intended to be paired with the generic React package, which is shipped as react to npm.
Installation
npm install react react-dom
Usage
In the browser
import { createRoot } from 'react-dom/client';
function App() {
return <div>Hello World</div>;
}
const root = createRoot(document.getElementById('root'));
root.render(<App />);
On the server
import { renderToPipeableStream } from 'react-dom/server';
function App() {
return <div>Hello World</div>;
}
function handleRequest(res) {
// ... in your server handler ...
const stream = renderToPipeableStream(<App />, {
onShellReady() {
res.statusCode = 200;
res.setHeader('Content-type', 'text/html');
stream.pipe(res);
},
// ...
});
}
API
react-dom
See https://react.dev/reference/react-dom
react-dom/client
See https://react.dev/reference/react-dom/client