UNPKG

@engie-group/fluid-design-system-react

Version:

Fluid Design System React

20 lines (17 loc) 625 B
import { isValidElement, Children, cloneElement } from 'react'; function extractChild(element) { const elementAsReactElement = element; if (!isValidElement(element) || !Children.count(elementAsReactElement.props.children)) { throw new Error(`Invalid element. Impossible to extract child`); } return elementAsReactElement.props.children; } function updateChild(element, child) { if (!isValidElement(element)) { throw new Error(`Invalid element. Impossible to update child`); } return cloneElement(element, { children: child }); } export { extractChild, updateChild };