import React from 'react'; export default function flattenReactChildrenToArray(nodeChildren, accumulated = []) { React.Children.forEach(nodeChildren, (childNode) => { accumulated.push(childNode); if (childNode && childNode.props && childNode.props.children) { flattenReactChildrenToArray(childNode.props.children, accumulated); } }); return accumulated; }