mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
Adds `getClientRects()` to fragment instances with a fixture test case. `Element.getClientRect` returns a collection of `DOMRect`s (see example of multiline span returning two `DOMRect` boxes). `fragmentInstance.getClientRects` here flattens those collections into an array of rects. |
||
|---|---|---|
| .. | ||
| 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