Skip to content

Commit c420621

Browse files
committed
Fix nits
1 parent 3f2cf0a commit c420621

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

src/content/blog/2024/04/01/react-19.md

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ const [submitAction, state, isPending] = useActionState(async () => {
111111

112112
`useActionState` accepts a function (the "Action"), and returns a new Action to call. This works because Actions compose. When the new Action is called, `useActionState` will return the last result of the Action as `data`, and the pending state of the Action as `pending`.
113113

114+
<Note>
115+
116+
`React.useActionState` was previously called `ReactDOM.useFormState` in the Canary releases, but we've renamed it and deprecated `useFormState`.
117+
118+
See [#28491](https://github.com/facebook/react/pull/28491) for more info.
119+
120+
</Note>
121+
114122
For more information, see the docs for [`useActionState`](/reference/react/useActionState).
115123

116124
### Form Actions {/*form-actions*/}
@@ -148,7 +156,7 @@ function NameInput() {
148156
}
149157
```
150158

151-
`useFormStatus` works like Context for the nearest `<form>` element, returning it's `pending` state, the last submitted form `data`, and the `action`.
159+
`useFormStatus` works like Context for the nearest `<form>` element, returning its `pending` state, the last submitted form `data`, and the `action`.
152160

153161
For more information, see the docs for [`useFormStatus`](/reference/react-dom/hooks/useFormStatus).
154162

@@ -180,7 +188,7 @@ return (
180188
</form>
181189
);
182190
```
183-
The `useOptimisitc` hook will immediately render the `optimisticName` while the `updateName` request is in progress. When the update finishes, React will automatically switch back to the original `name` value.
191+
The `useOptimistic` hook will immediately render the `optimisticName` while the `updateName` request is in progress. When the update finishes or errors, React will automatically switch back to the original `name` value.
184192

185193
For more information, see the docs for [`useOptimistic`](/reference/react/useOptimistic).
186194

@@ -205,7 +213,7 @@ Or you can read context with `use`:
205213

206214
```js {1,5}
207215
import {use} from 'react';
208-
import ThemeContext from 'ThemeContext'
216+
import ThemeContext from './ThemeContext'
209217

210218
function ThemedPage({children}) {
211219
const theme = use(ThemeContext);
@@ -360,7 +368,7 @@ function Author({id}) {
360368
```
361369
```js
362370
// api
363-
import db from 'db';
371+
import db from './database';
364372

365373
app.get(`/api/notes/:id`, async (req, res) => {
366374
const note = await db.notes.get(id);
@@ -376,7 +384,7 @@ app.get(`/api/authors/:id`, async (req, res) => {
376384
With Server Components, you can read the data and render it in the component:
377385

378386
```js
379-
import db from 'db';
387+
import db from './database';
380388

381389
async function Note({id}) {
382390
// NOTE: loads *during* render.
@@ -449,7 +457,7 @@ A common misunderstanding is that Server Components are denoted by `"use server"
449457
In the following example, the `Notes` Server Component imports an `Expandable` Client Component that uses state to toggle it's `expanded` state:
450458
```js
451459
// Server Component
452-
import Exapandable from 'Expandable';
460+
import Exapandable from './Expandable';
453461

454462
async function Notes() {
455463
const notes = await db.notes.getAll();
@@ -472,7 +480,11 @@ export default function Expandable({children}) {
472480
const [expanded, setExpanded] = useState(false);
473481
return (
474482
<div>
475-
<button onClick={() => setExpanded(s => !s)}>Toggle</button>
483+
<button
484+
onClick={() => setExpanded(!expanded)}
485+
>
486+
Toggle
487+
</button>
476488
{expanded && children}
477489
</div>
478490
)
@@ -503,11 +515,11 @@ This works by first rendering `Notes` as a Server Component, and then instructin
503515

504516
Server Components introduce a new way to write Components using async/await. When you `await` in an async component, React will suspend and wait for the promise to resolve before resuming rendering. This works across server/client boundaries with streaming support for Suspense.
505517

506-
You can even start a promise on the server, and resume it on the client:
518+
You can even create a promise on the server, and await it on the client:
507519

508520
```js
509521
// Server Component
510-
import db from 'db';
522+
import db from './database';
511523

512524
async function Page({id}) {
513525
// Will suspend the Server Component.
@@ -565,7 +577,7 @@ Server Components can define Server Actions with the `"use server"` directive:
565577

566578
```js [[2, 7, "'use server'"], [1, 5, "emptyNoteAction"], [1, 12, "emptyNoteAction"]]
567579
// Server Component
568-
import Button from 'Button';
580+
import Button from './Button';
569581

570582
function EmptyNote () {
571583
async function emptyNoteAction() {
@@ -826,7 +838,9 @@ When the component unmounts, React will call the cleanup function returned from
826838

827839
<Note>
828840

829-
When the cleanup function is provided, React will not call the ref with `null`. In future versions, we will deprecate calling the ref with `null` as a way to reset the `ref`.
841+
Previously, React would call ref functions with `null` when unmounting the component. If your ref returns a cleanup function, React will skip this step.
842+
843+
In future versions, we will deprecate calling the ref with `null` when unmounting components.
830844

831845
</Note>
832846

@@ -961,7 +975,7 @@ React will try to recreate this component tree from scratch using the error boun
961975
962976
</ConsoleBlockMulti>
963977
964-
Additionally, we've added two new root options to compliment `onRecoverableError`:
978+
Additionally, we've added two new root options to complement `onRecoverableError`:
965979

966980
- `onCaughtError`: called when React catches an error in an Error Boundary.
967981
- `onUncaughtError`: called when an error is thrown and not caught by an Error Boundary.
@@ -971,7 +985,7 @@ For more info and examples, see the docs for [`createRoot`](/reference/react-dom
971985

972986
### Diffs for Hydration Errors {/*diffs-for-hydration-errors*/}
973987

974-
We also improved error reporting for hydration errors. For example, instead of logging multiple errors in DEV without any information about what mismatched:
988+
We also improved error reporting for hydration errors. For example, instead of logging multiple errors in DEV without any information about the mismatch:
975989

976990
<ConsoleBlockMulti>
977991

0 commit comments

Comments
 (0)