You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

19 lines
491 B

  1. import React from 'react';
  2. import { isFragment } from 'react-is';
  3. export default function toArray(children) {
  4. var ret = [];
  5. React.Children.forEach(children, function (child) {
  6. if (child === undefined || child === null) {
  7. return;
  8. }
  9. if (Array.isArray(child)) {
  10. ret = ret.concat(toArray(child));
  11. } else if (isFragment(child) && child.props) {
  12. ret = ret.concat(toArray(child.props.children));
  13. } else {
  14. ret.push(child);
  15. }
  16. });
  17. return ret;
  18. }