Skip to content

Commit 423a248

Browse files
authored
Note about special props in PropTypes typechecking
1 parent 91ac3d8 commit 423a248

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

content/warnings/special-props.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,17 @@ permalink: warnings/special-props.html
66

77
Most props on a JSX element are passed on to the component, however, there are two special props (`ref` and `key`) which are used by React, and are thus not forwarded to the component.
88

9-
For instance, attempting to access `this.props.key` from a component (eg. the render function) is not defined. If you need to access the same value within the child component, you should pass it as a different prop (ex: `<ListItemWrapper key={result.id} id={result.id} />`). While this may seem redundant, it's important to separate app logic from reconciling hints.
9+
For instance, attempting to access `this.props.key` from a component (eg. the render function) is not defined. If you need to access the same value within the child component, you should pass it as a different prop (ex: `<ListItemWrapper key={result.id} id={result.id} />`). While this may seem redundant, it's important to separate app logic from reconciling hints.
10+
11+
> Note:
12+
>
13+
> There is no need to validate special props using [PropTypes typechecking](https://reactjs.org/docs/typechecking-with-proptypes.html#proptypes).
14+
>
15+
> By defining `key` or `ref` PropTypes, React will try to access them during props validation phase in the development build.
16+
>
17+
> ```js
18+
> ListItemWrapper.propTypes = {
19+
> id: PropTypes.string,
20+
> key: PropTypes.string // WARNING
21+
> }
22+
> ```

0 commit comments

Comments
 (0)