utils.mjs 436 B

1234567891011121314
  1. import { Children, isValidElement } from 'react';
  2. const getChildKey = (child) => child.key || "";
  3. function onlyElements(children) {
  4. const filtered = [];
  5. // We use forEach here instead of map as map mutates the component key by preprending `.$`
  6. Children.forEach(children, (child) => {
  7. if (isValidElement(child))
  8. filtered.push(child);
  9. });
  10. return filtered;
  11. }
  12. export { getChildKey, onlyElements };