1 | /**
|
2 | * Copyright (c) 2013-present, Facebook, Inc.
|
3 | *
|
4 | * This source code is licensed under the MIT license found in the
|
5 | * LICENSE file in the root directory of this source tree.
|
6 | *
|
7 | */
|
8 | ;
|
9 |
|
10 | var _prodInvariant = require('./reactProdInvariant');
|
11 |
|
12 | var ReactElement = require('./ReactElement');
|
13 |
|
14 | var invariant = require('fbjs/lib/invariant');
|
15 |
|
16 | /**
|
17 | * Returns the first child in a collection of children and verifies that there
|
18 | * is only one child in the collection.
|
19 | *
|
20 | * See https://facebook.github.io/react/docs/top-level-api.html#react.children.only
|
21 | *
|
22 | * The current implementation of this function assumes that a single child gets
|
23 | * passed without a wrapper, but the purpose of this helper function is to
|
24 | * abstract away the particular structure of children.
|
25 | *
|
26 | * @param {?object} children Child collection structure.
|
27 | * @return {ReactElement} The first and only `ReactElement` contained in the
|
28 | * structure.
|
29 | */
|
30 | function onlyChild(children) {
|
31 | !ReactElement.isValidElement(children) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'React.Children.only expected to receive a single React element child.') : _prodInvariant('143') : void 0;
|
32 | return children;
|
33 | }
|
34 |
|
35 | module.exports = onlyChild; |
\ | No newline at end of file |