|
Last change
on this file since ba17441 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
1.1 KB
|
| Line | |
|---|
| 1 | # `react-dom`
|
|---|
| 2 |
|
|---|
| 3 | 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.
|
|---|
| 4 |
|
|---|
| 5 | ## Installation
|
|---|
| 6 |
|
|---|
| 7 | ```sh
|
|---|
| 8 | npm install react react-dom
|
|---|
| 9 | ```
|
|---|
| 10 |
|
|---|
| 11 | ## Usage
|
|---|
| 12 |
|
|---|
| 13 | ### In the browser
|
|---|
| 14 |
|
|---|
| 15 | ```js
|
|---|
| 16 | import { createRoot } from 'react-dom/client';
|
|---|
| 17 |
|
|---|
| 18 | function App() {
|
|---|
| 19 | return <div>Hello World</div>;
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 22 | const root = createRoot(document.getElementById('root'));
|
|---|
| 23 | root.render(<App />);
|
|---|
| 24 | ```
|
|---|
| 25 |
|
|---|
| 26 | ### On the server
|
|---|
| 27 |
|
|---|
| 28 | ```js
|
|---|
| 29 | import { renderToPipeableStream } from 'react-dom/server';
|
|---|
| 30 |
|
|---|
| 31 | function App() {
|
|---|
| 32 | return <div>Hello World</div>;
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | function handleRequest(res) {
|
|---|
| 36 | // ... in your server handler ...
|
|---|
| 37 | const stream = renderToPipeableStream(<App />, {
|
|---|
| 38 | onShellReady() {
|
|---|
| 39 | res.statusCode = 200;
|
|---|
| 40 | res.setHeader('Content-type', 'text/html');
|
|---|
| 41 | stream.pipe(res);
|
|---|
| 42 | },
|
|---|
| 43 | // ...
|
|---|
| 44 | });
|
|---|
| 45 | }
|
|---|
| 46 | ```
|
|---|
| 47 |
|
|---|
| 48 | ## API
|
|---|
| 49 |
|
|---|
| 50 | ### `react-dom`
|
|---|
| 51 |
|
|---|
| 52 | See https://react.dev/reference/react-dom
|
|---|
| 53 |
|
|---|
| 54 | ### `react-dom/client`
|
|---|
| 55 |
|
|---|
| 56 | See https://react.dev/reference/react-dom/client
|
|---|
| 57 |
|
|---|
| 58 | ### `react-dom/server`
|
|---|
| 59 |
|
|---|
| 60 | See https://react.dev/reference/react-dom/server
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.