Skip to content

Commit dfd4fa8

Browse files
authored
docs(en): merge reactjs.org/main into zh-hans.reactjs.org/main @ 20f0fe2
2 parents 8ced164 + e7fb1ba commit dfd4fa8

34 files changed

+948
-826
lines changed

beta/CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The documentation is divided into sections to cater to different learning styles
2020

2121
**[Learn React](https://beta.reactjs.org/learn)** is designed to introduce fundamental concepts in a step-by-step way. Each individual article in Learn React builds on the knowledge from the previous ones, so make sure not to add any "cyclical dependencies" between them. It is important that the reader can start with the first article and work their way to the last Learn React article without ever having to "look ahead" for a definition. This explains some ordering choices (e.g. that state is explained before events, or that "thinking in React" doesn't use refs). Learn React also serves as a reference manual for React concepts, so it is important to be very strict about their definitions and relationships between them.
2222

23-
**[API Reference](https://reactjs.org/reference)** is organized by APIs rather than concepts. It is intended to be exhaustive. Any corner cases or recommendations that were skipped for brevity in Learn React should be mentioned in the reference documentation for the corresponding APIs.
23+
**[API Reference](https://reactjs.org/apis)** is organized by APIs rather than concepts. It is intended to be exhaustive. Any corner cases or recommendations that were skipped for brevity in Learn React should be mentioned in the reference documentation for the corresponding APIs.
2424

2525
**Try to follow your own instructions.**
2626

beta/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"check-all": "npm-run-all prettier lint:fix tsc"
2323
},
2424
"dependencies": {
25-
"@codesandbox/sandpack-react": "0.13.9-experimental.6",
25+
"@codesandbox/sandpack-react": "0.13.11-experimental.0",
2626
"@docsearch/css": "3.0.0-alpha.41",
2727
"@docsearch/react": "3.0.0-alpha.41",
2828
"@headlessui/react": "^1.3.0",
@@ -100,6 +100,6 @@
100100
},
101101
"lint-staged": {
102102
"*.{js,ts,jsx,tsx,css}": "yarn prettier",
103-
"*.md": "yarn fix-headings"
103+
"src/**/*.md": "yarn fix-headings"
104104
}
105105
}

beta/plugins/md-layout-loader.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports = async function (src) {
2323
const layoutMap = {
2424
blog: 'Post',
2525
learn: 'Learn',
26-
reference: 'API',
26+
apis: 'API',
2727
};
2828
const layout = layoutMap[pageParentDir] || 'Home';
2929
const code =

beta/src/components/Layout/Footer.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ export function Footer() {
8989
</FooterLink>
9090
</div>
9191
<div className="flex flex-col">
92-
<FooterLink href="/reference" isHeader={true}>
92+
<FooterLink href="/apis" isHeader={true}>
9393
API Reference
9494
</FooterLink>
95-
<FooterLink href="/reference">React APIs</FooterLink>
96-
<FooterLink href="/reference/reactdom">React DOM APIs</FooterLink>
95+
<FooterLink href="/apis">React APIs</FooterLink>
96+
<FooterLink href="/apis/reactdom">React DOM APIs</FooterLink>
9797
</div>
9898
<div className="flex flex-col sm:col-start-2 xl:col-start-4">
9999
<FooterLink href="/" isHeader={true}>

beta/src/components/Layout/MarkdownPage.tsx

+1-8
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function MarkdownPage<
3434
}> = React.Children.toArray(children)
3535
.filter((child: any) => {
3636
if (child.props?.mdxType) {
37-
return ['h1', 'h2', 'h3', 'Challenges', 'Recipes', 'Recap'].includes(
37+
return ['h1', 'h2', 'h3', 'Challenges', 'Recap'].includes(
3838
child.props.mdxType
3939
);
4040
}
@@ -48,13 +48,6 @@ export function MarkdownPage<
4848
text: 'Challenges',
4949
};
5050
}
51-
if (child.props.mdxType === 'Recipes') {
52-
return {
53-
url: '#' + (child.props.titleId ?? 'examples'),
54-
depth: 0,
55-
text: child.props.titleText ?? 'Examples',
56-
};
57-
}
5851
if (child.props.mdxType === 'Recap') {
5952
return {
6053
url: '#recap',

beta/src/components/Layout/Nav/MobileNav.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import sidebarHome from '../../../sidebarHome.json';
1111
import sidebarLearn from '../../../sidebarLearn.json';
1212
import sidebarReference from '../../../sidebarReference.json';
1313

14-
function inferSection(pathname: string): 'learn' | 'reference' | 'home' {
14+
function inferSection(pathname: string): 'learn' | 'apis' | 'home' {
1515
if (pathname.startsWith('/learn')) {
1616
return 'learn';
17-
} else if (pathname.startsWith('/reference')) {
18-
return 'reference';
17+
} else if (pathname.startsWith('/apis')) {
18+
return 'apis';
1919
} else {
2020
return 'home';
2121
}
@@ -33,7 +33,7 @@ export function MobileNav() {
3333
case 'learn':
3434
tree = sidebarLearn.routes[0];
3535
break;
36-
case 'reference':
36+
case 'apis':
3737
tree = sidebarReference.routes[0];
3838
break;
3939
}
@@ -52,8 +52,8 @@ export function MobileNav() {
5252
Learn
5353
</TabButton>
5454
<TabButton
55-
isActive={section === 'reference'}
56-
onClick={() => setSection('reference')}>
55+
isActive={section === 'apis'}
56+
onClick={() => setSection('apis')}>
5757
API
5858
</TabButton>
5959
</div>

beta/src/components/Layout/Nav/Nav.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ const lightIcon = (
8686
</svg>
8787
);
8888

89-
function inferSection(pathname: string): 'learn' | 'reference' | 'home' {
89+
function inferSection(pathname: string): 'learn' | 'apis' | 'home' {
9090
if (pathname.startsWith('/learn')) {
9191
return 'learn';
92-
} else if (pathname.startsWith('/reference')) {
93-
return 'reference';
92+
} else if (pathname.startsWith('/apis')) {
93+
return 'apis';
9494
} else {
9595
return 'home';
9696
}
@@ -166,7 +166,7 @@ export default function Nav() {
166166
<NavLink href="/learn" isActive={section === 'learn'}>
167167
Learn
168168
</NavLink>
169-
<NavLink href="/reference" isActive={section === 'reference'}>
169+
<NavLink href="/apis" isActive={section === 'apis'}>
170170
API
171171
</NavLink>
172172
</div>

beta/src/components/Layout/useMediaQuery.tsx

+17-2
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,29 @@ const useMediaQuery = (width: number) => {
1717

1818
useEffect(() => {
1919
const media = window.matchMedia(`(max-width: ${width}px)`);
20-
media.addEventListener('change', updateTarget);
20+
21+
try {
22+
// Chrome & Firefox
23+
media.addEventListener('change', updateTarget);
24+
} catch {
25+
// @deprecated method - Safari <= iOS12
26+
media.addListener(updateTarget);
27+
}
2128

2229
// Check on mount (callback is not called until a change occurs)
2330
if (media.matches) {
2431
setTargetReached(true);
2532
}
2633

27-
return () => media.removeEventListener('change', updateTarget);
34+
return () => {
35+
try {
36+
// Chrome & Firefox
37+
media.removeEventListener('change', updateTarget);
38+
} catch {
39+
// @deprecated method - Safari <= iOS12
40+
media.removeListener(updateTarget);
41+
}
42+
};
2843
}, [updateTarget, width]);
2944

3045
return targetReached;

beta/src/components/MDX/Challenges/Challenges.tsx

+9-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as React from 'react';
66
import cn from 'classnames';
77
import {Button} from 'components/Button';
88
import {H2} from 'components/MDX/Heading';
9+
import {H4} from 'components/MDX/Heading';
910
import {Navigation} from './Navigation';
1011
import {IconHint} from '../../Icon/IconHint';
1112
import {IconSolution} from '../../Icon/IconSolution';
@@ -111,21 +112,24 @@ export function Challenges({
111112
return order === currentChallenge.order + 1;
112113
});
113114

115+
const Heading = isRecipes ? H4 : H2;
114116
return (
115-
<div className="max-w-7xl mx-auto py-4 md:py-12">
117+
<div className="max-w-7xl mx-auto py-4">
116118
<div
117119
className={cn(
118120
'border-gray-10 bg-card dark:bg-card-dark shadow-inner rounded-none -mx-5 sm:mx-auto sm:rounded-lg'
119121
)}>
120122
<div ref={scrollAnchorRef} className="py-2 px-5 sm:px-8 pb-0 md:pb-0">
121-
<H2
123+
<Heading
122124
id={titleId}
123125
className={cn(
124-
'text-3xl mb-2 leading-10 relative',
125-
isRecipes ? 'text-purple-50 dark:text-purple-30' : 'text-link'
126+
'mb-2 leading-10 relative',
127+
isRecipes
128+
? 'text-xl text-purple-50 dark:text-purple-30'
129+
: 'text-3xl text-link'
126130
)}>
127131
{titleText}
128-
</H2>
132+
</Heading>
129133
{challenges.length > 1 && (
130134
<Navigation
131135
currentChallenge={currentChallenge}

beta/src/components/MDX/ExpandableCallout.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const variantMap = {
2525
'linear-gradient(rgba(245, 249, 248, 0), rgba(245, 249, 248, 1)',
2626
},
2727
gotcha: {
28-
title: 'Gotcha',
28+
title: 'Pitfall',
2929
Icon: IconGotcha,
3030
containerClasses: 'bg-yellow-5 dark:bg-yellow-60 dark:bg-opacity-20',
3131
textColor: 'text-yellow-50 dark:text-yellow-40',

beta/src/components/MDX/HomepageHero.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function HomepageHero() {
2727
</YouWillLearnCard>
2828
</div>
2929
<div className="flex flex-col justify-center">
30-
<YouWillLearnCard title="API Reference" path="/reference">
30+
<YouWillLearnCard title="API Reference" path="/apis">
3131
<p>
3232
查阅 React Hooks 的 API
3333
签名,并通过可视化的代码图解来学习如何使用。

beta/src/components/MDX/Sandpack/index.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,7 @@ function Sandpack(props: SandpackProps) {
127127
<SandpackProvider
128128
template="react"
129129
customSetup={{...setup, files: files}}
130-
autorun={autorun}
131-
initMode="user-visible"
132-
initModeObserverOptions={{rootMargin: '1400px 0px'}}>
130+
autorun={autorun}>
133131
<CustomPreset
134132
isSingleFile={isSingleFile}
135133
showDevTools={showDevTools}

beta/src/components/useMenu.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from 'body-scroll-lock';
1111
import {useRouter} from 'next/router';
1212

13-
type SidebarNav = 'root' | 'docs' | 'reference';
13+
type SidebarNav = 'root' | 'docs' | 'apis';
1414
/**
1515
* Menu toggle that enables body scroll locking (for
1616
* iOS Mobile and Tablet, Android, desktop Safari/Chrome/Firefox)
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)