Skip to content

Commit 49c2d26

Browse files
authored
Update useEffectEvent docs for canary (#8025)
* Update useEffectEvent docs for canary * Clean up prefixed imports * Fix import * Update blog post link
1 parent 1b20061 commit 49c2d26

10 files changed

+203
-110
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14303,7 +14303,7 @@ useEffect(() => {
1430314303
}); // compiler inserted dependencies.
1430414304
```
1430514305

14306-
With this code, the React Compiler can infer the dependencies for you and insert them automatically so you don't need to see or write them. With features like [the IDE extension](#compiler-ide-extension) and [`useEffectEvent`](/reference/react/experimental_useEffectEvent), we can provide a CodeLens to show you what the Compiler inserted for times you need to debug, or to optimize by removing a dependency. This helps reinforce the correct mental model for writing Effects, which can run at any time to synchronize your component or hook's state with something else.
14306+
With this code, the React Compiler can infer the dependencies for you and insert them automatically so you don't need to see or write them. With features like [the IDE extension](#compiler-ide-extension) and [`useEffectEvent`](/reference/react/useEffectEvent), we can provide a CodeLens to show you what the Compiler inserted for times you need to debug, or to optimize by removing a dependency. This helps reinforce the correct mental model for writing Effects, which can run at any time to synchronize your component or hook's state with something else.
1430714307

1430814308
Our hope is that automatically inserting dependencies is not only easier to write, but that it also makes them easier to understand by forcing you to think in terms of what the Effect does, and not in component lifecycles.
1430914309

src/content/learn/escape-hatches.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,8 @@ This is not ideal. You want to re-connect to the chat only if the `roomId` has c
455455
```json package.json hidden
456456
{
457457
"dependencies": {
458-
"react": "experimental",
459-
"react-dom": "experimental",
458+
"react": "canary",
459+
"react-dom": "canary",
460460
"react-scripts": "latest",
461461
"toastify-js": "1.12.0"
462462
},
@@ -471,7 +471,7 @@ This is not ideal. You want to re-connect to the chat only if the `roomId` has c
471471

472472
```js
473473
import { useState, useEffect } from 'react';
474-
import { experimental_useEffectEvent as useEffectEvent } from 'react';
474+
import { useEffectEvent } from 'react';
475475
import { createConnection, sendMessage } from './chat.js';
476476
import { showNotification } from './notifications.js';
477477

src/content/learn/removing-effect-dependencies.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -609,11 +609,13 @@ function ChatRoom({ roomId }) {
609609
610610
### Do you want to read a value without "reacting" to its changes? {/*do-you-want-to-read-a-value-without-reacting-to-its-changes*/}
611611
612-
<Wip>
612+
<Canary>
613613
614-
This section describes an **experimental API that has not yet been released** in a stable version of React.
614+
**The `useEffectEvent` API is currently only available in React’s Canary and Experimental channels.**
615615
616-
</Wip>
616+
[Learn more about React’s release channels here.](/community/versioning-policy#all-release-channels)
617+
618+
</Canary>
617619
618620
Suppose that you want to play a sound when the user receives a new message unless `isMuted` is `true`:
619621
@@ -1262,8 +1264,8 @@ Is there a line of code inside the Effect that should not be reactive? How can y
12621264
```json package.json hidden
12631265
{
12641266
"dependencies": {
1265-
"react": "experimental",
1266-
"react-dom": "experimental",
1267+
"react": "canary",
1268+
"react-dom": "canary",
12671269
"react-scripts": "latest"
12681270
},
12691271
"scripts": {
@@ -1277,7 +1279,7 @@ Is there a line of code inside the Effect that should not be reactive? How can y
12771279
12781280
```js
12791281
import { useState, useEffect, useRef } from 'react';
1280-
import { experimental_useEffectEvent as useEffectEvent } from 'react';
1282+
import { useEffectEvent } from 'react';
12811283
import { FadeInAnimation } from './animation.js';
12821284

12831285
function Welcome({ duration }) {
@@ -1389,8 +1391,8 @@ Your Effect needs to read the latest value of `duration`, but you don't want it
13891391
```json package.json hidden
13901392
{
13911393
"dependencies": {
1392-
"react": "experimental",
1393-
"react-dom": "experimental",
1394+
"react": "canary",
1395+
"react-dom": "canary",
13941396
"react-scripts": "latest"
13951397
},
13961398
"scripts": {
@@ -1405,7 +1407,7 @@ Your Effect needs to read the latest value of `duration`, but you don't want it
14051407
```js
14061408
import { useState, useEffect, useRef } from 'react';
14071409
import { FadeInAnimation } from './animation.js';
1408-
import { experimental_useEffectEvent as useEffectEvent } from 'react';
1410+
import { useEffectEvent } from 'react';
14091411

14101412
function Welcome({ duration }) {
14111413
const ref = useRef(null);
@@ -1825,8 +1827,8 @@ Another of these functions only exists to pass some state to an imported API met
18251827
```json package.json hidden
18261828
{
18271829
"dependencies": {
1828-
"react": "experimental",
1829-
"react-dom": "experimental",
1830+
"react": "canary",
1831+
"react-dom": "canary",
18301832
"react-scripts": "latest",
18311833
"toastify-js": "1.12.0"
18321834
},
@@ -1907,7 +1909,7 @@ export default function App() {
19071909
19081910
```js src/ChatRoom.js active
19091911
import { useState, useEffect } from 'react';
1910-
import { experimental_useEffectEvent as useEffectEvent } from 'react';
1912+
import { useEffectEvent } from 'react';
19111913

19121914
export default function ChatRoom({ roomId, createConnection, onMessage }) {
19131915
useEffect(() => {
@@ -2120,8 +2122,8 @@ As a result, the chat re-connects only when something meaningful (`roomId` or `i
21202122
```json package.json hidden
21212123
{
21222124
"dependencies": {
2123-
"react": "experimental",
2124-
"react-dom": "experimental",
2125+
"react": "canary",
2126+
"react-dom": "canary",
21252127
"react-scripts": "latest",
21262128
"toastify-js": "1.12.0"
21272129
},
@@ -2189,7 +2191,7 @@ export default function App() {
21892191
21902192
```js src/ChatRoom.js active
21912193
import { useState, useEffect } from 'react';
2192-
import { experimental_useEffectEvent as useEffectEvent } from 'react';
2194+
import { useEffectEvent } from 'react';
21932195
import {
21942196
createEncryptedConnection,
21952197
createUnencryptedConnection,

src/content/learn/reusing-logic-with-custom-hooks.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -837,11 +837,13 @@ Every time your `ChatRoom` component re-renders, it passes the latest `roomId` a
837837
838838
### Passing event handlers to custom Hooks {/*passing-event-handlers-to-custom-hooks*/}
839839
840-
<Wip>
840+
<Canary>
841841
842-
This section describes an **experimental API that has not yet been released** in a stable version of React.
842+
**The `useEffectEvent` API is currently only available in React’s Canary and Experimental channels.**
843843
844-
</Wip>
844+
[Learn more about React’s release channels here.](/community/versioning-policy#all-release-channels)
845+
846+
</Canary>
845847
846848
As you start using `useChatRoom` in more components, you might want to let components customize its behavior. For example, currently, the logic for what to do when a message arrives is hardcoded inside the Hook:
847849
@@ -985,7 +987,7 @@ export default function ChatRoom({ roomId }) {
985987
986988
```js src/useChatRoom.js
987989
import { useEffect } from 'react';
988-
import { experimental_useEffectEvent as useEffectEvent } from 'react';
990+
import { useEffectEvent } from 'react';
989991
import { createConnection } from './chat.js';
990992

991993
export function useChatRoom({ serverUrl, roomId, onReceiveMessage }) {
@@ -1070,8 +1072,8 @@ export function showNotification(message, theme = 'dark') {
10701072
```json package.json hidden
10711073
{
10721074
"dependencies": {
1073-
"react": "experimental",
1074-
"react-dom": "experimental",
1075+
"react": "canary",
1076+
"react-dom": "canary",
10751077
"react-scripts": "latest",
10761078
"toastify-js": "1.12.0"
10771079
},
@@ -1666,7 +1668,7 @@ export default function App() {
16661668
16671669
```js src/useFadeIn.js active
16681670
import { useState, useEffect } from 'react';
1669-
import { experimental_useEffectEvent as useEffectEvent } from 'react';
1671+
import { useEffectEvent } from 'react';
16701672

16711673
export function useFadeIn(ref, duration) {
16721674
const [isRunning, setIsRunning] = useState(true);
@@ -1719,8 +1721,8 @@ html, body { min-height: 300px; }
17191721
```json package.json hidden
17201722
{
17211723
"dependencies": {
1722-
"react": "experimental",
1723-
"react-dom": "experimental",
1724+
"react": "canary",
1725+
"react-dom": "canary",
17241726
"react-scripts": "latest"
17251727
},
17261728
"scripts": {
@@ -2208,8 +2210,8 @@ It looks like your `useInterval` Hook accepts an event listener as an argument.
22082210
```json package.json hidden
22092211
{
22102212
"dependencies": {
2211-
"react": "experimental",
2212-
"react-dom": "experimental",
2213+
"react": "canary",
2214+
"react-dom": "canary",
22132215
"react-scripts": "latest"
22142216
},
22152217
"scripts": {
@@ -2252,7 +2254,7 @@ export function useCounter(delay) {
22522254
22532255
```js src/useInterval.js
22542256
import { useEffect } from 'react';
2255-
import { experimental_useEffectEvent as useEffectEvent } from 'react';
2257+
import { useEffectEvent } from 'react';
22562258

22572259
export function useInterval(onTick, delay) {
22582260
useEffect(() => {
@@ -2279,8 +2281,8 @@ With this change, both intervals work as expected and don't interfere with each
22792281
```json package.json hidden
22802282
{
22812283
"dependencies": {
2282-
"react": "experimental",
2283-
"react-dom": "experimental",
2284+
"react": "canary",
2285+
"react-dom": "canary",
22842286
"react-scripts": "latest"
22852287
},
22862288
"scripts": {
@@ -2324,7 +2326,7 @@ export function useCounter(delay) {
23242326
23252327
```js src/useInterval.js active
23262328
import { useEffect } from 'react';
2327-
import { experimental_useEffectEvent as useEffectEvent } from 'react';
2329+
import { useEffectEvent } from 'react';
23282330

23292331
export function useInterval(callback, delay) {
23302332
const onTick = useEffectEvent(callback);

0 commit comments

Comments
 (0)