cloneElement.js 635 B

1234567891011121314151617181920212223242526
  1. import {
  2. createElement
  3. } from './MayElement';
  4. export function cloneElement(element, additionalProps) {
  5. var type = element.type;
  6. var props = element.props;
  7. var mergeProps = {};
  8. Object.assign(mergeProps, props, additionalProps);
  9. var config = {};
  10. if (element.key) {
  11. config.key = element.key;
  12. }
  13. if (element.ref) {
  14. config.ref = element.ref;
  15. }
  16. for (const key in mergeProps) {
  17. if (key !== 'children') {
  18. config[key] = mergeProps[key];
  19. }
  20. }
  21. var children = mergeProps.children;
  22. var ret = createElement(type, config, children);
  23. return ret;
  24. }