Skip to content

Instantly share code, notes, and snippets.

@jsdf
Created September 8, 2015 23:32
Show Gist options
  • Save jsdf/658bb65211eb2bce54d7 to your computer and use it in GitHub Desktop.
Save jsdf/658bb65211eb2bce54d7 to your computer and use it in GitHub Desktop.

Revisions

  1. jsdf created this gist Sep 8, 2015.
    11 changes: 11 additions & 0 deletions recursiveReactChildrenToArray.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    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;
    }