UNPKG

603 BJavaScriptView Raw
1// @flow
2'use strict'
3const React = require('react')
4const formatChildren = require('./base-format-children')
5
6function applyChildren (key/*: string */, element/*: any */, children/*: ?mixed[] */) {
7 if (process.env.NODE_ENV !== 'production' && !React.isValidElement(element)) {
8 throw new Error(JSON.stringify(element) + ' is not a valid element')
9 }
10
11 // $FlowFixMe it doesn't think any arguments are passed
12 return React.cloneElement.apply(
13 React,
14 [ element, { key: element.key || key } ].concat(children || [])
15 )
16}
17
18exports.formatChildren = formatChildren.bind(null, applyChildren)