Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/site_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Use Node.js 20.x
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: 20.x

- name: Install deps and build (with cache)
uses: bahmutov/npm-install@v1.7.10
uses: bahmutov/npm-install@v1.8.32

- name: Lint codebase
run: yarn ci-check
60 changes: 30 additions & 30 deletions src/content/community/conferences.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,6 @@ Do you know of a local React.js conference? Add it here! (Please keep the list c

## Upcoming Conferences {/*upcoming-conferences*/}

### Reactathon 2023 {/*reactathon-2023*/}
May 2 - 3, 2023. San Francisco, CA, USA

[Website](https://reactathon.com) - [Twitter](https://twitter.com/reactathon) - [YouTube](https://www.youtube.com/realworldreact)

### RemixConf 2023 {/*remixconf-2023*/}
May, 2023. Salt Lake City, UT

[Website](https://remix.run/conf/2023) - [Twitter](https://twitter.com/remix_run)

### App.js Conf 2023 {/*appjs-conf-2023*/}
May 10 - 12, 2023. In-person in Kraków, Poland + remote

[Website](https://appjs.co) - [Twitter](https://twitter.com/appjsconf)

### Chain React 2023 {/*chain-react-2023*/}
May 17 - 19, 2023. Portland, OR, USA

[Website](https://chainreactconf.com/) - [Twitter](https://twitter.com/ChainReactConf) - [Facebook](https://www.facebook.com/ChainReactConf/) - [Youtube](https://www.youtube.com/channel/UCwpSzVt7QpLDbCnPXqR97-g/playlists)

### Render(ATL) 2023 🍑 {/*renderatl-2023-*/}
May 31 - June 2, 2023. Atlanta, GA, USA

[Website](https://renderatl.com) - [Discord](https://www.renderatl.com/discord) - [Twitter](https://twitter.com/renderATL) - [Instagram](https://www.instagram.com/renderatl/) - [Facebook](https://www.facebook.com/renderatl/) - [LinkedIn](https://www.linkedin.com/company/renderatl) - [Podcast](https://www.renderatl.com/culture-and-code#/)

### React Summit 2023 {/*react-summit-2023*/}
June 2 & 6, 2023. In-person in Amsterdam, Netherlands + remote first interactivity (hybrid event)

[Website](https://reactsummit.com) - [Twitter](https://twitter.com/reactsummit) - [Facebook](https://www.facebook.com/reactamsterdam) - [Videos](https://portal.gitnation.org/events/react-summit-2023)

### React Norway 2023 {/*react-norway-2023*/}
June 16th, 2023. Larvik, Norway

Expand Down Expand Up @@ -82,6 +52,36 @@ December 8 & 12, 2023. In-person in Berlin, Germany + remote first interactivity

## Past Conferences {/*past-conferences*/}

### React Summit 2023 {/*react-summit-2023*/}
June 2 & 6, 2023. In-person in Amsterdam, Netherlands + remote first interactivity (hybrid event)

[Website](https://reactsummit.com) - [Twitter](https://twitter.com/reactsummit) - [Facebook](https://www.facebook.com/reactamsterdam) - [Videos](https://portal.gitnation.org/events/react-summit-2023)

### Render(ATL) 2023 🍑 {/*renderatl-2023-*/}
May 31 - June 2, 2023. Atlanta, GA, USA

[Website](https://renderatl.com) - [Discord](https://www.renderatl.com/discord) - [Twitter](https://twitter.com/renderATL) - [Instagram](https://www.instagram.com/renderatl/) - [Facebook](https://www.facebook.com/renderatl/) - [LinkedIn](https://www.linkedin.com/company/renderatl) - [Podcast](https://www.renderatl.com/culture-and-code#/)

### Chain React 2023 {/*chain-react-2023*/}
May 17 - 19, 2023. Portland, OR, USA

[Website](https://chainreactconf.com/) - [Twitter](https://twitter.com/ChainReactConf) - [Facebook](https://www.facebook.com/ChainReactConf/) - [Youtube](https://www.youtube.com/channel/UCwpSzVt7QpLDbCnPXqR97-g/playlists)

### App.js Conf 2023 {/*appjs-conf-2023*/}
May 10 - 12, 2023. In-person in Kraków, Poland + remote

[Website](https://appjs.co) - [Twitter](https://twitter.com/appjsconf)

### RemixConf 2023 {/*remixconf-2023*/}
May, 2023. Salt Lake City, UT

[Website](https://remix.run/conf/2023) - [Twitter](https://twitter.com/remix_run)

### Reactathon 2023 {/*reactathon-2023*/}
May 2 - 3, 2023. San Francisco, CA, USA

[Website](https://reactathon.com) - [Twitter](https://twitter.com/reactathon) - [YouTube](https://www.youtube.com/realworldreact)

### React Miami 2023 {/*react-miami-2023*/}
April 20 - 21, 2023. Miami, FL, USA

Expand Down
2 changes: 1 addition & 1 deletion src/content/learn/manipulating-the-dom-with-refs.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Then, use it to declare a ref inside your component:
const myRef = useRef(null);
```

Finally, pass it to the DOM node as the `ref` attribute:
Finally, pass your ref as the `ref` attribute to the JSX tag for which you want to get the DOM node:

```js
<div ref={myRef}>
Expand Down
2 changes: 1 addition & 1 deletion src/content/learn/you-might-not-need-an-effect.md
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,7 @@ It would be nice if there was a way to tell React that when `savedContact.id` is

<Solution>

Split the `EditContact` component in two. Move all the form state into the inner `EditForm` component. Export the outer `EditContact` component, and make it pass `savedContact.id` as the `key` to the inner `EditContact` component. As a result, the inner `EditForm` component resets all of the form state and recreates the DOM whenever you select a different contact.
Split the `EditContact` component in two. Move all the form state into the inner `EditForm` component. Export the outer `EditContact` component, and make it pass `savedContact.id` as the `key` to the inner `EditForm` component. As a result, the inner `EditForm` component resets all of the form state and recreates the DOM whenever you select a different contact.

<Sandpack>

Expand Down
2 changes: 1 addition & 1 deletion src/content/reference/react-dom/components/option.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The [built-in browser `<option>` component](https://developer.mozilla.org/en-US/

### `<option>` {/*option*/}

The [built-in browser `<option>` component](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select) lets you render an option inside a [`<select>`](/reference/react-dom/components/select) box.
The [built-in browser `<option>` component](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option) lets you render an option inside a [`<select>`](/reference/react-dom/components/select) box.

```js
<select>
Expand Down
2 changes: 1 addition & 1 deletion src/content/reference/react-dom/components/progress.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ To display a progress indicator, render the [built-in browser `<progress>`](http
Additionally, `<progress>` supports these props:

* [`max`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/progress#attr-max): A number. Specifies the maximum `value`. Defaults to `1`.
* [`value`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/progress#attr-value): A number between `0` and `max`, or `null` for intermedinate progress. Specifies how much was done.
* [`value`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/progress#attr-value): A number between `0` and `max`, or `null` for indeterminate progress. Specifies how much was done.

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ Streaming does not need to wait for React itself to load in the browser, or for

**Only Suspense-enabled data sources will activate the Suspense component.** They include:

- Data fetching with Suspense-enabled frameworks like [Relay](https://relay.dev/docs/guided-tour/rendering/loading-states/) and [Next.js](https://nextjs.org/docs/advanced-features/react-18)
- Data fetching with Suspense-enabled frameworks like [Relay](https://relay.dev/docs/guided-tour/rendering/loading-states/) and [Next.js](https://nextjs.org/docs/getting-started/react-essentials)
- Lazy-loading component code with [`lazy`](/reference/react/lazy)

Suspense **does not** detect when data is fetched inside an Effect or event handler.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ Streaming does not need to wait for React itself to load in the browser, or for

**Only Suspense-enabled data sources will activate the Suspense component.** They include:

- Data fetching with Suspense-enabled frameworks like [Relay](https://relay.dev/docs/guided-tour/rendering/loading-states/) and [Next.js](https://nextjs.org/docs/advanced-features/react-18)
- Data fetching with Suspense-enabled frameworks like [Relay](https://relay.dev/docs/guided-tour/rendering/loading-states/) and [Next.js](https://nextjs.org/docs/getting-started/react-essentials)
- Lazy-loading component code with [`lazy`](/reference/react/lazy)

Suspense **does not** detect when data is fetched inside an Effect or event handler.
Expand Down
2 changes: 1 addition & 1 deletion src/content/reference/react/Suspense.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ async function getAlbums() {

**Only Suspense-enabled data sources will activate the Suspense component.** They include:

- Data fetching with Suspense-enabled frameworks like [Relay](https://relay.dev/docs/guided-tour/rendering/loading-states/) and [Next.js](https://nextjs.org/docs/advanced-features/react-18)
- Data fetching with Suspense-enabled frameworks like [Relay](https://relay.dev/docs/guided-tour/rendering/loading-states/) and [Next.js](https://nextjs.org/docs/getting-started/react-essentials)
- Lazy-loading component code with [`lazy`](/reference/react/lazy)

Suspense **does not** detect when data is fetched inside an Effect or event handler.
Expand Down
16 changes: 16 additions & 0 deletions src/content/reference/react/directives.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title: "Directives"
---

<Intro>

React uses two directives to provide instructions to [bundlers compatible with React Server Components](/learn/start-a-new-react-project#bleeding-edge-react-frameworks).

</Intro>

---

## Source code directives {/*source-code-directives*/}

* [`'use client'`](/reference/react/use-client) marks source files whose components execute on the client.
* [`'use server'`](/reference/react/use-server) marks server-side functions that can be called from client-side code.
57 changes: 57 additions & 0 deletions src/content/reference/react/use-client.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
title: "'use client'"
---

<Note>

These directives are needed only if you're [using React Server Components](/learn/start-a-new-react-project#bleeding-edge-react-frameworks) or building a library compatible with them.

</Note>


<Intro>

`'use client'` marks source files whose components execute on the client.

</Intro>

<InlineToc />

---

## Reference {/*reference*/}

### `'use client'` {/*use-client*/}

Add `'use client';` at the very top of a file to mark that the file (including any child components it uses) executes on the client, regardless of where it's imported.

```js
'use client';

import { useState } from 'react';

export default function RichTextEditor(props) {
// ...
```

When a file marked `'use client'` is imported from a server component, [compatible bundlers](/learn/start-a-new-react-project#bleeding-edge-react-frameworks) will treat the import as the "cut-off point" between server-only code and client code. Components at or below this point in the module graph can use client-only React features like [`useState`](/reference/react/useState).

#### Caveats {/*caveats*/}

* It's not necessary to add `'use client'` to every file that uses client-only React features, only the files that are imported from server component files. `'use client'` denotes the _boundary_ between server-only and client code; any components further down the tree will automatically be executed on the client. In order to be rendered from server components, components exported from `'use client'` files must have serializable props.
* When a `'use client'` file is imported from a server file, the imported values can be rendered as a React component or passed via props to a client component. Any other use will throw an exception.
* When a `'use client'` file is imported from another client file, the directive has no effect. This allows you to write client-only components that are simultaneously usable from server and client components.
* All the code in `'use client'` file as well as any modules it imports (directly or indirectly) will become a part of the client module graph and must be sent to and executed by the client in order to be rendered by the browser. To reduce client bundle size and take full advantage of the server, move state (and the `'use client'` directives) lower in the tree when possible, and pass rendered server components [as children](/learn/passing-props-to-a-component#passing-jsx-as-children) to client components.
* Because props are serialized across the server–client boundary, note that the placement of these directives can affect the amount of data sent to the client; avoid data structures that are larger than necessary.
* Components like a `<MarkdownRenderer>` that use neither server-only nor client-only features should generally not be marked with `'use client'`. That way, they can render exclusively on the server when used from a server component, but they'll be added to the client bundle when used from a client component.
* Libraries published to npm should include `'use client'` on exported React components that can be rendered with serializable props that use client-only React features, to allow those components to be imported and rendered by server components. Otherwise, users will need to wrap library components in their own `'use client'` files which can be cumbersome and prevents the library from moving logic to the server later. When publishing prebundled files to npm, ensure that `'use client'` source files end up in a bundle marked with `'use client'`, separate from any bundle containing exports that can be used directly on the server.
* Client components will still run as part of server-side rendering (SSR) or build-time static site generation (SSG), which act as clients to transform React components' initial render output to HTML that can be rendered before JavaScript bundles are downloaded. But they can't use server-only features like reading directly from a database.
* Directives like `'use client'` must be at the very beginning of a file, above any imports or other code (comments above directives are OK). They must be written with single or double quotes, not backticks. (The `'use xyz'` directive format somewhat resembles the `useXyz()` Hook naming convention, but the similarity is coincidental.)

## Usage {/*usage*/}

<Wip>

This section is incomplete. See also the [Next.js documentation for Server Components](https://beta.nextjs.org/docs/rendering/server-and-client-components).

</Wip>
48 changes: 48 additions & 0 deletions src/content/reference/react/use-server.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: "'use server'"
---

<Wip>

This section is incomplete.

These directives are needed only if you're [using React Server Components](/learn/start-a-new-react-project#bleeding-edge-react-frameworks) or building a library compatible with them.

</Wip>


<Intro>

`'use server'` marks server-side functions that can be called from client-side code.

</Intro>

<InlineToc />

---

## Reference {/*reference*/}

### `'use server'` {/*use-server*/}

Add `'use server';` at the very top of an async function to mark that the function can be executed by the client.

```js
async function addToCart(data) {
'use server';
// ...
}

// <ProductDetailPage addToCart={addToCart} />
```

This function can be passed to the client. When called on the client, it will make a network request to the server that includes a serialized copy of any arguments passed. If the server function returns a value, that value will be serialized and returned to the client.

Alternatively, add `'use server';` at the very top of a file to mark all exports within that file as async server functions that can be used anywhere, including imported in client component files.

#### Caveats {/*caveats*/}

* Remember that parameters to functions marked with `'use server'` are fully client-controlled. For security, always treat them as untrusted input, making sure to validate and escape the arguments as appropriate.
* To avoid the confusion that might result from mixing client- and server-side code in the same file, `'use server'` can only be used in server-side files; the resulting functions can be passed to client components through props.
* Because the underlying network calls are always asynchronous, `'use server'` can be used only on async functions.
* Directives like `'use server'` must be at the very beginning of their function or file, above any other code including imports (comments above directives are OK). They must be written with single or double quotes, not backticks. (The `'use xyz'` directive format somewhat resembles the `useXyz()` Hook naming convention, but the similarity is coincidental.)
2 changes: 1 addition & 1 deletion src/content/reference/react/useDeferredValue.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ During updates, the <CodeStep step={2}>deferred value</CodeStep> will "lag behin

This example assumes you use one of Suspense-enabled data sources:

- Data fetching with Suspense-enabled frameworks like [Relay](https://relay.dev/docs/guided-tour/rendering/loading-states/) and [Next.js](https://nextjs.org/docs/advanced-features/react-18)
- Data fetching with Suspense-enabled frameworks like [Relay](https://relay.dev/docs/guided-tour/rendering/loading-states/) and [Next.js](https://nextjs.org/docs/getting-started/react-essentials)
- Lazy-loading component code with [`lazy`](/reference/react/lazy)

[Learn more about Suspense and its limitations.](/reference/react/Suspense)
Expand Down
2 changes: 1 addition & 1 deletion src/content/reference/react/useEffect.md
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ function ChatRoom({ roomId }) {
}
```
**To remove a dependency, you need to ["prove" to the linter *doesn't need* to be a dependency.](/learn/removing-effect-dependencies#removing-unnecessary-dependencies)** For example, you can move `serverUrl` out of your component to prove that it's not reactive and won't change on re-renders:
**To remove a dependency, you need to ["prove" to the linter that it *doesn't need* to be a dependency.](/learn/removing-effect-dependencies#removing-unnecessary-dependencies)** For example, you can move `serverUrl` out of your component to prove that it's not reactive and won't change on re-renders:
```js {1,8}
const serverUrl = 'https://localhost:1234'; // Not a reactive value anymore
Expand Down
2 changes: 1 addition & 1 deletion src/content/reference/react/useLayoutEffect.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ useLayoutEffect(setup, dependencies?)

### `useLayoutEffect(setup, dependencies?)` {/*useinsertioneffect*/}

Call `useLayoutEffect` perform the layout measurements before the browser repaints the screen:
Call `useLayoutEffect` to perform the layout measurements before the browser repaints the screen:

```js
import { useState, useRef, useLayoutEffect } from 'react';
Expand Down
2 changes: 1 addition & 1 deletion src/content/reference/react/useRef.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function MyComponent() {

If you *have to* read [or write](/reference/react/useState#storing-information-from-previous-renders) something during rendering, [use state](/reference/react/useState) instead.

When you break these rules, your component might still work, but most of the newer features we're adding to React will rely on these expectations. Read more about [keeping your components pure.](/learn/keeping-components-pure#where-you-can-cause-side-effects)
When you break these rules, your component might still work, but most of the newer features we're adding to React will rely on these expectations. Read more about [keeping your components pure.](/learn/keeping-components-pure#where-you-_can_-cause-side-effects)

</Pitfall>

Expand Down
14 changes: 14 additions & 0 deletions src/sidebarReference.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@
}
]
},
{
"title": "Directives",
"path": "/reference/react/directives",
"routes": [
{
"title": "'use client'",
"path": "/reference/react/use-client"
},
{
"title": "'use server'",
"path": "/reference/react/use-server"
}
]
},
{
"hasSectionHeader": true,
"sectionHeader": "react-dom@18.2.0"
Expand Down