Skip to content

Commit 3a94eb0

Browse files
authored
Clarify callback parameters
Clarifies the callback parameters for React.Children.map() and React.Children.forEach() by noting that they can also contain an optional `index` parameter as a second argument.
1 parent c8161bd commit 3a94eb0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

content/docs/reference-react.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,15 @@ Verifies the object is a React element. Returns `true` or `false`.
154154
#### `React.Children.map`
155155

156156
```javascript
157-
React.Children.map(children, function[(thisArg)])
157+
React.Children.map(children, function(thisArg, [index]))
158158
```
159159

160-
Invokes a function on every immediate child contained within `children` with `this` set to `thisArg`. If `children` is a keyed fragment or array it will be traversed: the function will never be passed the container objects. If children is `null` or `undefined`, returns `null` or `undefined` rather than an array.
160+
Invokes a function on every immediate child contained within `children` with `this` set to `thisArg`. The optional `index` parameter refers to the index of the current child in the array. If `children` is a keyed fragment or array it will be traversed: the function will never be passed the container objects. If children is `null` or `undefined`, returns `null` or `undefined` rather than an array.
161161

162162
#### `React.Children.forEach`
163163

164164
```javascript
165-
React.Children.forEach(children, function[(thisArg)])
165+
React.Children.forEach(children, function(thisArg, [index]))
166166
```
167167

168168
Like [`React.Children.map()`](#reactchildrenmap) but does not return an array.

0 commit comments

Comments
 (0)