1 | /**
|
2 | * Copyright 2013-present, Facebook, Inc.
|
3 | * All rights reserved.
|
4 | *
|
5 | * This source code is licensed under the BSD-style license found in the
|
6 | * LICENSE file in the root directory of this source tree. An additional grant
|
7 | * of patent rights can be found in the PATENTS file in the same directory.
|
8 | *
|
9 | */
|
10 | ;
|
11 |
|
12 | var _prodInvariant = require('./reactProdInvariant');
|
13 |
|
14 | var ReactElement = require('./ReactElement');
|
15 |
|
16 | var invariant = require('fbjs/lib/invariant');
|
17 |
|
18 | /**
|
19 | * Returns the first child in a collection of children and verifies that there
|
20 | * is only one child in the collection.
|
21 | *
|
22 | * See https://facebook.github.io/react/docs/top-level-api.html#react.children.only
|
23 | *
|
24 | * The current implementation of this function assumes that a single child gets
|
25 | * passed without a wrapper, but the purpose of this helper function is to
|
26 | * abstract away the particular structure of children.
|
27 | *
|
28 | * @param {?object} children Child collection structure.
|
29 | * @return {ReactElement} The first and only `ReactElement` contained in the
|
30 | * structure.
|
31 | */
|
32 | function onlyChild(children) {
|
33 | !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;
|
34 | return children;
|
35 | }
|
36 |
|
37 | module.exports = onlyChild; |
\ | No newline at end of file |