Some checks failed
CI / go (push) Waiting to run
CI / docker (push) Waiting to run
CI / lint-go (push) Waiting to run
CI / lint-docs (push) Waiting to run
CI / check-paperclip (push) Waiting to run
Deploy static site / Deploy to GitHub Pages (push) Has been cancelled
Deploy static site / Deploy via Docker to hatch.surf (push) Has been cancelled
Resolved conflicts by taking GitHub versions for: - .dockerignore, .gitignore, Dockerfile, README.md, docker-compose.yml Kept deploy.sh updated to: - Pull from GitHub (primary source) - Push to Gitea (push-mirror) - Build from site/ directory (GitHub structure) Co-Authored-By: Paperclip <noreply@paperclip.ing>
61 lines
1.1 KiB
Markdown
61 lines
1.1 KiB
Markdown
# `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
|
|
|
|
```sh
|
|
npm install react react-dom
|
|
```
|
|
|
|
## Usage
|
|
|
|
### In the browser
|
|
|
|
```js
|
|
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
|
|
|
|
```js
|
|
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
|
|
|
|
### `react-dom/server`
|
|
|
|
See https://react.dev/reference/react-dom/server
|