MCPcopy
hub / github.com/facebook/react / onlyChild

Function onlyChild

packages/react/src/ReactChildren.js:446–454  ·  view source on GitHub ↗

* Returns the first child in a collection of children and verifies that there * is only one child in the collection. * * See https://reactjs.org/docs/react-api.html#reactchildrenonly * * The current implementation of this function assumes that a single child gets * passed without a wrapper, bu

(children: T)

Source from the content-addressed store, hash-verified

444 * structure.
445 */
446function onlyChild<T>(children: T): T {
447 if (!isValidElement(children)) {
448 throw new Error(
449 'React.Children.only expected to receive a single React element child.',
450 );
451 }
452
453 return children;
454}
455
456export {
457 forEachChildren as forEach,

Callers

nothing calls this directly

Calls 1

isValidElementFunction · 0.90

Tested by

no test coverage detected