1/** 2 * Copyright 2013-2014, 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 * @providesModule onlyChild 10 */ 11"use strict"; 12 13var ReactElement = require('ReactElement'); 14 15var invariant = require('invariant'); 16 17/** 18 * Returns the first child in a collection of children and verifies that there 19 * is only one child in the collection. The current implementation of this 20 * function assumes that a single child gets passed without a wrapper, but the 21 * purpose of this helper function is to abstract away the particular structure 22 * of children. 23 * 24 * @param {?object} children Child collection structure. 25 * @return {ReactComponent} The first and only `ReactComponent` contained in the 26 * structure. 27 */ 28function onlyChild(children) { 29 invariant( 30 ReactElement.isValidElement(children), 31 'onlyChild must be passed a children with exactly one child.' 32 ); 33 return children; 34} 35 36module.exports = onlyChild; 37 38