Skip to content

Commit f6e1413

Browse files
authored
docs: add tranalse in /reference/react-dom/components (#1837)
2 parents 61c376e + 0e52242 commit f6e1413

File tree

1 file changed

+18
-18
lines changed
  • src/content/reference/react-dom/components

1 file changed

+18
-18
lines changed

src/content/reference/react-dom/components/index.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ React 支持所有浏览器内置的 [HTML](https://developer.mozilla.org/zh-CN/
3232

3333
---
3434

35-
## Resource and Metadata Components {/*resource-and-metadata-components*/}
35+
## 资源和元数据组件 {/*resource-and-metadata-components*/}
3636

37-
These built-in browser components let you load external resources or annotate the document with metadata:
37+
通过这些内置浏览器组件,您可以加载外部资源或为文档添加元数据注释:
3838

3939
* [`<link>`](/reference/react-dom/components/link)
4040
* [`<meta>`](/reference/react-dom/components/meta)
4141
* [`<script>`](/reference/react-dom/components/script)
4242
* [`<style>`](/reference/react-dom/components/style)
4343
* [`<title>`](/reference/react-dom/components/title)
4444

45-
They are special in React because React can render them into the document head, suspend while resources are loading, and enact other behaviors that are described on the reference page for each specific component.
45+
它们在 React 中是特殊的,因为 React 可以将它们渲染到文档头部,在资源加载时暂停,并执行参考页面中针对每个特定组件描述的其他行为。
4646

4747
---
4848

@@ -166,27 +166,27 @@ React 支持所有浏览器内置的组件,包括:
166166

167167
如果你使用 [`is`](https://developer.mozilla.org/zh-CN/docs/Web/HTML/Global_attributes/is) 属性渲染一个内置的浏览器 HTML 元素,它也会被视为自定义元素。
168168

169-
#### Setting values on custom elements {/*attributes-vs-properties*/}
169+
#### 在自定义元素上设置值 {/*attributes-vs-properties*/}
170170

171-
Custom elements have two methods of passing data into them:
171+
自定义元素有两种数据传递方法:
172172

173-
1) Attributes: Which are displayed in markup and can only be set to string values
174-
2) Properties: Which are not displayed in markup and can be set to arbitrary JavaScript values
173+
1) Attributes:显示在标记中,只能设置为字符串值
174+
2) Properties:不在标记中显示,可设置为任意 JavaScript
175175

176-
By default, React will pass values bound in JSX as attributes:
176+
默认情况下,React 会将 JSX 中绑定的值作为 attributes 传递:
177177

178178
```jsx
179179
<my-element value="Hello, world!"></my-element>
180180
```
181181

182-
Non-string JavaScript values passed to custom elements will be serialized by default:
182+
默认情况下,传递给自定义元素的非字符串 JavaScript 值将被序列化:
183183

184184
```jsx
185-
// Will be passed as `"1,2,3"` as the output of `[1,2,3].toString()`
185+
// 将以 `[1,2,3].toString()` 的输出结果 `"1,2,3"` 的形式传递
186186
<my-element value={[1,2,3]}></my-element>
187187
```
188188

189-
React will, however, recognize an custom element's property as one that it may pass arbitrary values to if the property name shows up on the class during construction:
189+
不过,如果自定义元素的属性名称在构建过程中出现在类上,React 就会将其识别为可以传递任意值的 arbitrary
190190

191191
<Sandpack>
192192

@@ -205,8 +205,8 @@ root.render(<App />);
205205
export class MyElement extends HTMLElement {
206206
constructor() {
207207
super();
208-
// The value here will be overwritten by React
209-
// when initialized as an element
208+
// 初始化为元素时
209+
// 此处的值将被 React 覆盖
210210
this.value = undefined;
211211
}
212212

@@ -224,9 +224,9 @@ export function App() {
224224

225225
</Sandpack>
226226

227-
#### Listening for events on custom elements {/*custom-element-events*/}
227+
#### 监听自定义元素上的事件 {/*custom-element-events*/}
228228

229-
A common pattern when using custom elements is that they may dispatch [`CustomEvent`s](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent) rather than accept a function to call when an event occur. You can listen for these events using an `on` prefix when binding to the event via JSX.
229+
使用自定义元素时的一个常见模式是,它们可能会派发 [`自定义事件`](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent),而不是在事件发生时接受函数调用。在通过 JSX 绑定事件时,可以使用 `on` 前缀来监听这些事件。
230230

231231
<Sandpack>
232232

@@ -285,12 +285,12 @@ export function App() {
285285

286286
<Note>
287287

288-
Events are case-sensitive and support dashes (`-`). Preserve the casing of the event and include all dashes when listening for custom element's events:
288+
事件区分大小写,并支持破折号(`-`)。在监听自定义元素事件时,请保留事件的大小写并包含所有破折号:
289289

290290
```jsx
291-
// Listens for `say-hi` events
291+
// 监听 `say-hi` 事件
292292
<my-element onsay-hi={console.log}></my-element>
293-
// Listens for `sayHi` events
293+
// 监听 `sayHi` 事件
294294
<my-element onsayHi={console.log}></my-element>
295295
```
296296

0 commit comments

Comments
 (0)