Skip to content

Commit 9e6704e

Browse files
committed
docs(en): merging all conflicts
2 parents d7062fa + 5f09d9f commit 9e6704e

File tree

2 files changed

+43
-12
lines changed

2 files changed

+43
-12
lines changed

src/content/blog/index.md

+6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ title: React Blog
44

55
<Intro>
66

7+
<<<<<<< HEAD
78
这个博客是 React 团队更新的官方来源。任何重要的内容,包括发布说明或弃用通知,都会首先在这里发布。
9+
=======
10+
This blog is the official source for the updates from the React team. Anything important, including release notes or deprecation notices, will be posted here first.
11+
12+
You can also follow the [@react.dev](https://bsky.app/profile/react.dev) account on Bluesky, or [@reactjs](https://twitter.com/reactjs) account on Twitter, but you won’t miss anything essential if you only read this blog.
13+
>>>>>>> 5f09d9f4467871955d794aa5fbc7bf3c4e7a5f4f
814
915
你也可以在 Bluesky 上关注 [@react.dev](https://bsky.app/profiles/react.js) 的账号,Twitter 的 [@reactjs](https://twitter.com/reactjs) 账号,但如果你只阅读这个博客,你也不会错过任何重要的内容。
1016
</Intro>

src/content/learn/passing-data-deeply-with-context.md

+37-12
Original file line numberDiff line numberDiff line change
@@ -471,15 +471,19 @@ import { LevelContext } from './LevelContext.js';
471471
export default function Section({ level, children }) {
472472
return (
473473
<section className="section">
474-
<LevelContext.Provider value={level}>
474+
<LevelContext value={level}>
475475
{children}
476-
</LevelContext.Provider>
476+
</LevelContext>
477477
</section>
478478
);
479479
}
480480
```
481481

482+
<<<<<<< HEAD
482483
这告诉 React:“如果在 `<Section>` 组件中的任何子组件请求 `LevelContext`,给他们这个 `level`。”组件会使用 UI 树中在它上层最近的那个 `<LevelContext.Provider>` 传递过来的值。
484+
=======
485+
This tells React: "if any component inside this `<Section>` asks for `LevelContext`, give them this `level`." The component will use the value of the nearest `<LevelContext>` in the UI tree above it.
486+
>>>>>>> 5f09d9f4467871955d794aa5fbc7bf3c4e7a5f4f
483487
484488
<Sandpack>
485489

@@ -517,9 +521,9 @@ import { LevelContext } from './LevelContext.js';
517521
export default function Section({ level, children }) {
518522
return (
519523
<section className="section">
520-
<LevelContext.Provider value={level}>
524+
<LevelContext value={level}>
521525
{children}
522-
</LevelContext.Provider>
526+
</LevelContext>
523527
</section>
524528
);
525529
}
@@ -569,9 +573,15 @@ export const LevelContext = createContext(1);
569573

570574
这与原始代码的运行结果相同,但是你不需要向每个 `Heading` 组件传递 `level` 参数了!取而代之的是,它通过访问上层最近的 `Section` 来“断定”它的标题级别:
571575

576+
<<<<<<< HEAD
572577
1. 你将一个 `level` 参数传递给 `<Section>`
573578
2. `Section` 把它的子元素包在 `<LevelContext.Provider value={level}>` 里面。
574579
3. `Heading` 使用 `useContext(LevelContext)` 访问上层最近的 `LevelContext` 提供的值。
580+
=======
581+
1. You pass a `level` prop to the `<Section>`.
582+
2. `Section` wraps its children into `<LevelContext value={level}>`.
583+
3. `Heading` asks the closest value of `LevelContext` above with `useContext(LevelContext)`.
584+
>>>>>>> 5f09d9f4467871955d794aa5fbc7bf3c4e7a5f4f
575585
576586
## 在相同的组件中使用并提供 context {/*using-and-providing-context-from-the-same-component*/}
577587

@@ -599,9 +609,9 @@ export default function Section({ children }) {
599609
const level = useContext(LevelContext);
600610
return (
601611
<section className="section">
602-
<LevelContext.Provider value={level + 1}>
612+
<LevelContext value={level + 1}>
603613
{children}
604-
</LevelContext.Provider>
614+
</LevelContext>
605615
</section>
606616
);
607617
}
@@ -647,9 +657,9 @@ export default function Section({ children }) {
647657
const level = useContext(LevelContext);
648658
return (
649659
<section className="section">
650-
<LevelContext.Provider value={level + 1}>
660+
<LevelContext value={level + 1}>
651661
{children}
652-
</LevelContext.Provider>
662+
</LevelContext>
653663
</section>
654664
);
655665
}
@@ -780,9 +790,9 @@ export default function Section({ children, isFancy }) {
780790
'section ' +
781791
(isFancy ? 'fancy' : '')
782792
}>
783-
<LevelContext.Provider value={level + 1}>
793+
<LevelContext value={level + 1}>
784794
{children}
785-
</LevelContext.Provider>
795+
</LevelContext>
786796
</section>
787797
);
788798
}
@@ -868,6 +878,7 @@ Context 不局限于静态值。如果你在下一次渲染时传递不同的值
868878
869879
<Recap>
870880
881+
<<<<<<< HEAD
871882
* Context 使组件向其下方的整个树提供信息。
872883
* 传递 Context 的方法:
873884
1. 通过 `export const MyContext = createContext(defaultValue)` 创建并导出 context。
@@ -876,6 +887,16 @@ Context 不局限于静态值。如果你在下一次渲染时传递不同的值
876887
* Context 会穿过中间的任何组件。
877888
* Context 可以让你写出 “较为通用” 的组件。
878889
* 在使用 context 之前,先试试传递 props 或者将 JSX 作为 `children` 传递。
890+
=======
891+
* Context lets a component provide some information to the entire tree below it.
892+
* To pass context:
893+
1. Create and export it with `export const MyContext = createContext(defaultValue)`.
894+
2. Pass it to the `useContext(MyContext)` Hook to read it in any child component, no matter how deep.
895+
3. Wrap children into `<MyContext value={...}>` to provide it from a parent.
896+
* Context passes through any components in the middle.
897+
* Context lets you write components that "adapt to their surroundings".
898+
* Before you use context, try passing props or passing JSX as `children`.
899+
>>>>>>> 5f09d9f4467871955d794aa5fbc7bf3c4e7a5f4f
879900
880901
</Recap>
881902
@@ -1026,7 +1047,11 @@ li {
10261047
10271048
移除掉所有组件中的 `imageSize` 参数。
10281049
1050+
<<<<<<< HEAD
10291051
`Context.js` 中创建并导出 `ImageSizeContext`。然后用 `<ImageSizeContext.Provider value={imageSize}>` 包裹住整个列表来向下传递值,最后在 `PlaceImage` 中使用 `useContext(ImageSizeContext)` 来读取它。
1052+
=======
1053+
Create and export `ImageSizeContext` from `Context.js`. Then wrap the List into `<ImageSizeContext value={imageSize}>` to pass the value down, and `useContext(ImageSizeContext)` to read it in the `PlaceImage`:
1054+
>>>>>>> 5f09d9f4467871955d794aa5fbc7bf3c4e7a5f4f
10301055
10311056
<Sandpack>
10321057
@@ -1040,7 +1065,7 @@ export default function App() {
10401065
const [isLarge, setIsLarge] = useState(false);
10411066
const imageSize = isLarge ? 150 : 100;
10421067
return (
1043-
<ImageSizeContext.Provider
1068+
<ImageSizeContext
10441069
value={imageSize}
10451070
>
10461071
<label>
@@ -1055,7 +1080,7 @@ export default function App() {
10551080
</label>
10561081
<hr />
10571082
<List />
1058-
</ImageSizeContext.Provider>
1083+
</ImageSizeContext>
10591084
)
10601085
}
10611086

0 commit comments

Comments
 (0)