Skip to content

Commit b19da79

Browse files
committed
docs(en): merging all conflicts
2 parents f2101ab + d6c4c0f commit b19da79

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

src/content/blog/2025/04/23/react-labs-view-transitions-activity-and-more.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ You can try them by upgrading React packages to the most recent experimental ver
5151

5252
Read on to learn how to use these features in your app, or check out the newly published docs:
5353

54-
- [`<ViewTransition>`](/reference/react/ViewTransition): A component lets you activate an animation for a Transition.
54+
- [`<ViewTransition>`](/reference/react/ViewTransition): A component that lets you activate an animation for a Transition.
5555
- [`addTransitionType`](/reference/react/addTransitionType): A function that allows you to specify the cause of a Transition.
56-
- [`<Activity>`](/reference/react/Activity): A component that lets you hide and show part of the UI.
56+
- [`<Activity>`](/reference/react/Activity): A component that lets you hide and show parts of the UI.
5757

5858
## View Transitions {/*view-transitions*/}
5959

@@ -14355,4 +14355,4 @@ This research is still early. We'll share more, and what the new APIs will look
1435514355

1435614356
---
1435714357

14358-
_Thanks to [Aurora Scharff](https://bsky.app/profile/aurorascharff.no), [Dan Abramov](https://bsky.app/profile/danabra.mov), [Eli White](https://twitter.com/Eli_White), [Lauren Tan](https://bsky.app/profile/no.lol), [Luna Wei](https://github.com/lunaleaps), [Matt Carroll](https://twitter.com/mattcarrollcode), [Jack Pope](https://jackpope.me), [Jason Bonta](https://threads.net/someextent), [Jordan Brown](https://github.com/jbrown215), [Jordan Eldredge](https://bsky.app/profile/capt.dev), [Mofei Zhang](https://threads.net/z_mofei), [Sebastien Lorber](https://bsky.app/profile/sebastienlorber.com), [Sebastian Markbåge](https://bsky.app/profile/sebmarkbage.calyptus.eu), and [Tim Yung](https://github.com/yungsters) for reviewing this post._
14358+
_Thanks to [Aurora Scharff](https://bsky.app/profile/aurorascharff.no), [Dan Abramov](https://bsky.app/profile/danabra.mov), [Eli White](https://twitter.com/Eli_White), [Lauren Tan](https://bsky.app/profile/no.lol), [Luna Wei](https://github.com/lunaleaps), [Matt Carroll](https://twitter.com/mattcarrollcode), [Jack Pope](https://jackpope.me), [Jason Bonta](https://threads.net/someextent), [Jordan Brown](https://github.com/jbrown215), [Jordan Eldredge](https://bsky.app/profile/capt.dev), [Mofei Zhang](https://threads.net/z_mofei), [Sebastien Lorber](https://bsky.app/profile/sebastienlorber.com), [Sebastian Markbåge](https://bsky.app/profile/sebmarkbage.calyptus.eu), and [Tim Yung](https://github.com/yungsters) for reviewing this post._

src/content/reference/react/useOptimistic.md

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,39 +66,47 @@ function AppContainer() {
6666

6767

6868
```js src/App.js
69-
import { useOptimistic, useState, useRef } from "react";
69+
import { useOptimistic, useState, useRef, startTransition } from "react";
7070
import { deliverMessage } from "./actions.js";
7171

72-
function Thread({ messages, sendMessage }) {
72+
function Thread({ messages, sendMessageAction }) {
7373
const formRef = useRef();
74-
async function formAction(formData) {
74+
function formAction(formData) {
7575
addOptimisticMessage(formData.get("message"));
7676
formRef.current.reset();
77-
await sendMessage(formData);
77+
sendMessageAction(formData);
7878
}
7979
const [optimisticMessages, addOptimisticMessage] = useOptimistic(
8080
messages,
8181
(state, newMessage) => [
82-
...state,
8382
{
8483
text: newMessage,
8584
sending: true
86-
}
85+
},
86+
...state,
8787
]
8888
);
8989

9090
return (
9191
<>
92+
<form action={formAction} ref={formRef}>
93+
<input type="text" name="message" placeholder="Hello!" />
94+
<button type="submit">Send</button>
95+
</form>
9296
{optimisticMessages.map((message, index) => (
9397
<div key={index}>
9498
{message.text}
9599
{!!message.sending && <small>(发送中……)</small>}
96100
</div>
97101
))}
102+
<<<<<<< HEAD
98103
<form action={formAction} ref={formRef}>
99104
<input type="text" name="message" placeholder="你好!" />
100105
<button type="submit">发送</button>
101106
</form>
107+
=======
108+
109+
>>>>>>> d6c4c0fee514d06e329d08774bf2f37a7e4e594e
102110
</>
103111
);
104112
}
@@ -107,11 +115,15 @@ export default function App() {
107115
const [messages, setMessages] = useState([
108116
{ text: "你好,在这儿!", sending: false, key: 1 }
109117
]);
110-
async function sendMessage(formData) {
111-
const sentMessage = await deliverMessage(formData.get("message"));
112-
setMessages((messages) => [...messages, { text: sentMessage }]);
118+
function sendMessageAction(formData) {
119+
startTransition(async () => {
120+
const sentMessage = await deliverMessage(formData.get("message"));
121+
startTransition(() => {
122+
setMessages((messages) => [{ text: sentMessage }, ...messages]);
123+
})
124+
})
113125
}
114-
return <Thread messages={messages} sendMessage={sendMessage} />;
126+
return <Thread messages={messages} sendMessageAction={sendMessageAction} />;
115127
}
116128
```
117129

0 commit comments

Comments
 (0)