Skip to content

Commit 8d6531f

Browse files
committed
Merge branch 'main' of https://github.com/reactjs/reactjs.org into sync-119177b8
2 parents b4c1d22 + 119177b commit 8d6531f

16 files changed

+1259
-146
lines changed

beta/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"eslint-plugin-import": "2.x",
6868
"eslint-plugin-jsx-a11y": "6.x",
6969
"eslint-plugin-react": "7.x",
70-
"eslint-plugin-react-hooks": "experimental",
70+
"eslint-plugin-react-hooks": "^0.0.0-experimental-fabef7a6b-20221215",
7171
"fs-extra": "^9.0.1",
7272
"globby": "^11.0.1",
7373
"gray-matter": "^4.0.2",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
diff --git a/node_modules/@codemirror/lang-javascript/dist/index.js b/node_modules/@codemirror/lang-javascript/dist/index.js
2+
index d089f6b..db09ea6 100644
3+
--- a/node_modules/@codemirror/lang-javascript/dist/index.js
4+
+++ b/node_modules/@codemirror/lang-javascript/dist/index.js
5+
@@ -131,7 +131,9 @@ const javascriptLanguage = /*@__PURE__*/LRLanguage.define({
6+
JSXText: tags.content,
7+
"JSXStartTag JSXStartCloseTag JSXSelfCloseEndTag JSXEndTag": tags.angleBracket,
8+
"JSXIdentifier JSXNameSpacedName": tags.tagName,
9+
- "JSXAttribute/JSXIdentifier JSXAttribute/JSXNameSpacedName": tags.attributeName
10+
+ "JSXAttribute/JSXIdentifier JSXAttribute/JSXNameSpacedName": tags.attributeName,
11+
+ "JSXAttribute/JSXLowerIdentifier JSXAttribute/JSXNameSpacedName": tags.attributeName,
12+
+ "JSXBuiltin/JSXIdentifier": tags.standard(tags.tagName),
13+
})
14+
]
15+
}),

beta/patches/@codesandbox+sandpack-react+1.15.5.patch

+26
Large diffs are not rendered by default.

beta/patches/@lezer+javascript+0.15.2.patch

+345
Large diffs are not rendered by default.

beta/src/components/MDX/CodeBlock/CodeBlock.tsx

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
*/
44

55
import cn from 'classnames';
6-
import {highlightTree} from '@codemirror/highlight';
6+
import {highlightTree, HighlightStyle, tags} from '@codemirror/highlight';
77
import {javascript} from '@codemirror/lang-javascript';
88
import {html} from '@codemirror/lang-html';
99
import {css} from '@codemirror/lang-css';
10-
import {HighlightStyle, tags} from '@codemirror/highlight';
1110
import rangeParser from 'parse-numeric-range';
1211
import {CustomTheme} from '../Sandpack/Themes';
1312

@@ -233,7 +232,7 @@ function getSyntaxHighlight(theme: any): HighlightStyle {
233232
class: classNameToken('static'),
234233
},
235234
{
236-
tag: tags.tagName,
235+
tag: tags.standard(tags.tagName),
237236
class: classNameToken('tag'),
238237
},
239238
{tag: tags.variableName, class: classNameToken('plain')},
@@ -244,7 +243,7 @@ function getSyntaxHighlight(theme: any): HighlightStyle {
244243
},
245244
{
246245
// Highlight function definition differently (eg: functional component def in React)
247-
tag: tags.definition(tags.function(tags.variableName)),
246+
tag: [tags.definition(tags.function(tags.variableName)), tags.tagName],
248247
class: classNameToken('definition'),
249248
},
250249
{

beta/src/content/apis/react/useEffect.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -1653,11 +1653,11 @@ function Page({ url, shoppingCart }) {
16531653
}
16541654
```
16551655
1656-
**What if you want to log a new page visit after every `url` change, but *not* if only the `shoppingCart` changes?** You can't exclude `shoppingCart` from dependencies without breaking the [reactivity rules.](#specifying-reactive-dependencies) However, you can express that you *don't want* a piece of code to "react" to changes even though it is called from inside an Effect. To do this, [declare an *Event function*](/learn/separating-events-from-effects#declaring-an-event-function) with the [`useEvent`](/apis/react/useEvent) Hook, and move the code that reads `shoppingCart` inside of it:
1656+
**What if you want to log a new page visit after every `url` change, but *not* if only the `shoppingCart` changes?** You can't exclude `shoppingCart` from dependencies without breaking the [reactivity rules.](#specifying-reactive-dependencies) However, you can express that you *don't want* a piece of code to "react" to changes even though it is called from inside an Effect. [Declare an *Effect Event*](/learn/separating-events-from-effects#declaring-an-effect-event) with the [`useEffectEvent`](/apis/react/useEffectEvent) Hook, and move the code that reads `shoppingCart` inside of it:
16571657
16581658
```js {2-4,7,8}
16591659
function Page({ url, shoppingCart }) {
1660-
const onVisit = useEvent(visitedUrl => {
1660+
const onVisit = useEffectEvent(visitedUrl => {
16611661
logVisit(visitedUrl, shoppingCart.length)
16621662
});
16631663

@@ -1668,9 +1668,9 @@ function Page({ url, shoppingCart }) {
16681668
}
16691669
```
16701670
1671-
**Event functions are not reactive and don't need to be specified as dependencies of your Effect.** This is what lets you put non-reactive code (where you can read the latest value of some props and state) inside of them. For example, by reading `shoppingCart` inside of `onVisit`, you ensure that `shoppingCart` won't re-run your Effect.
1671+
**Effect Events are not reactive and must always be omitted from dependencies of your Effect.** This is what lets you put non-reactive code (where you can read the latest value of some props and state) inside of them. For example, by reading `shoppingCart` inside of `onVisit`, you ensure that `shoppingCart` won't re-run your Effect. In the future, the linter will support `useEffectEvent` and check that you omit Effect Events from dependencies.
16721672
1673-
[Read more about how Event functions let you separate reactive and non-reactive code.](/learn/separating-events-from-effects#reading-latest-props-and-state-with-event-functions)
1673+
[Read more about how Effect Events let you separate reactive and non-reactive code.](/learn/separating-events-from-effects#reading-latest-props-and-state-with-effect-events)
16741674
16751675
16761676
---
@@ -1751,6 +1751,8 @@ function ChatRoom({ roomId }) {
17511751
17521752
* If your Effect wasn't caused by an interaction (like a click), React will let the browser **paint the updated screen first before running your Effect.** If your Effect is doing something visual (for example, positioning a tooltip), and the delay is noticeable (for example, it flickers), you need to replace `useEffect` with [`useLayoutEffect`.](/apis/react/useLayoutEffect)
17531753
1754+
* Even if your Effect was caused by an interaction (like a click), **the browser may repaint the screen before processing the state updates inside your Effect.** Usually, that's what you want. However, if you must block the browser from repainting the screen, you need to replace `useEffect` with [`useLayoutEffect`.](/apis/react/useLayoutEffect)
1755+
17541756
* Effects **only run on the client.** They don't run during server rendering.
17551757
17561758
---
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
title: useEffectEvent
3+
---
4+
5+
<Wip>
6+
7+
**This API is experimental and is not available in a stable version of React yet.**
8+
9+
See [`useEffectEvent` RFC](https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md) for details.
10+
11+
</Wip>
12+
13+
14+
<Intro>
15+
16+
`useEffectEvent` is a React Hook that lets you extract non-reactive logic into an [Effect Event.](/learn/separating-events-from-effects#declaring-an-effect-event)
17+
18+
```js
19+
const onSomething = useEffectEvent(callback)
20+
```
21+
22+
</Intro>
23+
24+
<InlineToc />

beta/src/content/apis/react/useEvent.md

-22
This file was deleted.

0 commit comments

Comments
 (0)