import React from 'react' ; import { FCWithName } from '../common/types' ; param children export const getChildrenAsArray = ( children ) : React . ReactElement [ ] => React . Children . toArray ( children ) as React . ReactElement [ ] ; param children param componentName export const getComponentFromChildren = ( children , componentName ) : React . ReactElement [ ] [ ] => { const childrenAsArray = [ ... getChildrenAsArray ( children ) ] ; const componentIndex = childrenAsArray . findIndex ( ( child ) => ( child . type as FCWithName ) ?. componentName === componentName ) ; const component = componentIndex >= 0 ? childrenAsArray . splice ( componentIndex , 1 ) : [ ] ; return [ component , childrenAsArray ] ; } ;