From 007cf55872af59092579faaf8fb5cd8a4cf650a5 Mon Sep 17 00:00:00 2001 From: Nick Presta Date: Wed, 7 Oct 2015 19:12:45 -0400 Subject: [PATCH] Add docs for `React.Children.toArray` in 0.14.0. * Update the docs to change return type of `React.Children.map` from `object` to `array`. (cherry picked from commit 319b37409769ee32f6a3f5a80a986298f8fd06e4) --- docs/docs/ref-01-top-level-api.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/docs/ref-01-top-level-api.md b/docs/docs/ref-01-top-level-api.md index 948c319621..4fdcdfd5b0 100644 --- a/docs/docs/ref-01-top-level-api.md +++ b/docs/docs/ref-01-top-level-api.md @@ -97,10 +97,10 @@ Verifies the object is a ReactElement. #### React.Children.map ```javascript -object React.Children.map(object children, function fn [, object thisArg]) +array React.Children.map(object children, function fn [, object thisArg]) ``` -Invoke `fn` on every immediate child contained within `children` with `this` set to `thisArg`. If `children` is a nested object or array it will be traversed: `fn` will never be passed the container objects. If children is `null` or `undefined` returns `null` or `undefined` rather than an empty object. +Invoke `fn` on every immediate child contained within `children` with `this` set to `thisArg`. If `children` is a nested object or array it will be traversed: `fn` will never be passed the container objects. If children is `null` or `undefined` returns `null` or `undefined` rather than an array. #### React.Children.forEach @@ -108,7 +108,7 @@ Invoke `fn` on every immediate child contained within `children` with `this` set React.Children.forEach(object children, function fn [, object thisArg]) ``` -Like `React.Children.map()` but does not return an object. +Like `React.Children.map()` but does not return an array. #### React.Children.count @@ -126,6 +126,14 @@ object React.Children.only(object children) Return the only child in `children`. Throws otherwise. +#### React.Children.toArray + +```javascript +array React.Children.toArray(object children) +``` + +Return the `children` opaque data structure as a flat array with keys assigned to each child. Useful if you want to manipulate collections of children in your render methods, especially if you want to reorder or slice `this.props.children` before passing it down. + ## ReactDOM The `react-dom` package provides DOM-specific methods that can be used at the top level of your app and as an escape hatch to get outside of the React model if you need to. Most of your components should not need to use this module.