You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/warnings/unknown-prop.md
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,38 +1,38 @@
1
1
---
2
-
title: Unknown Prop Warning
2
+
title: 未知属性警告
3
3
---
4
4
5
-
The unknown-prop warning will fire if you attempt to render a DOM element with a prop that is not recognized by React as a legal DOM attribute/property. You should ensure that your DOM elements do not have spurious props floating around.
5
+
如果尝试使用 React 不认识的属性来渲染 DOM 元素,将会触发未知属性警告。你应该确保 DOM 元素没有无法识别的冗余属性。
6
6
7
-
There are a couple of likely reasons this warning could be appearing:
7
+
出现此警告的可能原因有以下几个:
8
8
9
-
1.Are you using `{...props}`or`cloneElement(element, props)`? When copying props to a child component, you should ensure that you are not accidentally forwarding props that were intended only for the parent component. See common fixes for this problem below.
2.You are using a non-standard DOM attribute on a native DOM node, perhaps to represent custom data. If you are trying to attach custom data to a standard DOM element, consider using a custom data attribute as described [on MDN](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_data_attributes).
11
+
2.也许是为了展示自定义数据,你正在将非标准的 DOM 属性应用于 DOM 节点。如果你想将自定义数据附加到标准 DOM 元素上,请考虑使用自定义数据属性,如 [MDN](https://developer.mozilla.org/zh-CN/docs/Web/Guide/HTML/Using_data_attributes) 中所述。
12
12
13
-
3. React does not yet recognize the attribute you specified. This will likely be fixed in a future version of React. React will allow you to pass it without a warning if you write the attribute name lowercase.
4.You are using a React component without an upper case, for example `<myButton />`. React interprets it as a DOM tag because React JSX transform uses the upper vs. lower case convention to distinguish between user-defined components and DOM tags. For your own React components, use PascalCase. For example, write `<MyButton />`instead of `<myButton />`.
15
+
4.如果你使用一个首字母小写的 React 组件,如 `<myButton />`,React 会将其解释为 DOM 标签,因为 React JSX 使用大小写约定来区分用户自定义组件与 DOM 标签。对于自定义 React 组件,请使用 PascalCase 命名。例如,`<myButton />`应该写为 `<MyButton />`。
16
16
17
17
---
18
18
19
-
If you get this warning because you pass props like `{...props}`, your parent component needs to "consume" any prop that is intended for the parent component and not intended for the child component. Example:
**Good:** The spread syntax can be used to pull variables off props, and put the remaining props into a variable.
35
+
**正确的做法**:使用展开运算符获取其他属性,并将这些属性放在一个变量中。
36
36
37
37
```js
38
38
functionMyDiv(props) {
@@ -45,7 +45,7 @@ function MyDiv(props) {
45
45
}
46
46
```
47
47
48
-
**Good:** You can also assign the props to a new object and delete the keys that you're using from the new object. Be sure not to delete the props from the original `this.props`object, since that object should be considered immutable.
0 commit comments