parent
4bc465a16f
commit
bb49abea23
|
@ -13,38 +13,48 @@ npm install react react-dom
|
|||
### In the browser
|
||||
|
||||
```js
|
||||
var React = require('react');
|
||||
var ReactDOM = require('react-dom');
|
||||
import { createRoot } from 'react-dom';
|
||||
|
||||
function MyComponent() {
|
||||
function App() {
|
||||
return <div>Hello World</div>;
|
||||
}
|
||||
|
||||
ReactDOM.render(<MyComponent />, node);
|
||||
const root = createRoot(document.getElementById('root'));
|
||||
root.render(<App />);
|
||||
```
|
||||
|
||||
### On the server
|
||||
|
||||
```js
|
||||
var React = require('react');
|
||||
var ReactDOMServer = require('react-dom/server');
|
||||
import { renderToPipeableStream } from 'react-dom/server';
|
||||
|
||||
function MyComponent() {
|
||||
function App() {
|
||||
return <div>Hello World</div>;
|
||||
}
|
||||
|
||||
ReactDOMServer.renderToString(<MyComponent />);
|
||||
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`
|
||||
|
||||
- `findDOMNode`
|
||||
- `render`
|
||||
- `unmountComponentAtNode`
|
||||
See https://reactjs.org/docs/react-dom.html
|
||||
|
||||
### `react-dom/client`
|
||||
|
||||
See https://reactjs.org/docs/react-dom-client.html
|
||||
|
||||
### `react-dom/server`
|
||||
|
||||
- `renderToString`
|
||||
- `renderToStaticMarkup`
|
||||
See https://reactjs.org/docs/react-dom-server.html
|
||||
|
|
|
@ -6,8 +6,32 @@ The `react` package contains only the functionality necessary to define React co
|
|||
|
||||
**Note:** by default, React will be in development mode. The development version includes extra warnings about common mistakes, whereas the production version includes extra performance optimizations and strips all error messages. Don't forget to use the [production build](https://reactjs.org/docs/optimizing-performance.html#use-the-production-build) when deploying your application.
|
||||
|
||||
## Example Usage
|
||||
## Usage
|
||||
|
||||
```js
|
||||
var React = require('react');
|
||||
import { useState } from 'react';
|
||||
import { createRoot } from 'react-dom';
|
||||
|
||||
function Counter() {
|
||||
const [count, setCount] = useState(0);
|
||||
return (
|
||||
<>
|
||||
<h1>{count}</h1>
|
||||
<button onClick={() => setCount(count + 1)}>
|
||||
Increment
|
||||
</button>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
const root = createRoot(document.getElementById('root'));
|
||||
root.render(<App />);
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
See https://reactjs.org/
|
||||
|
||||
## API
|
||||
|
||||
See https://reactjs.org/docs/react-api.html
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# use-sync-external-store
|
||||
|
||||
Backwards compatible shim for React's `useSyncExternalStore`. Works with any React that supports hooks.
|
||||
Backwards-compatible shim for [`React.useSyncExternalStore`](https://reactjs.org/docs/hooks-reference.html#usesyncexternalstore). Works with any React that supports Hooks.
|
||||
|
||||
Until `useSyncExternalStore` is documented, refer to https://github.com/reactwg/react-18/discussions/86
|
||||
See also https://github.com/reactwg/react-18/discussions/86.
|
||||
|
|
Loading…
Reference in New Issue