luy
Version:
所谓类```React```框架就是**和React用法一模一样**的框架。其实当初制造这个框架的目的是为了能更好的学习React内部结构,了解其原理而制作的玩具。但是随着框架的渐渐成长,代码越来越多,我还是决定将其发展下去. 
20 lines (17 loc) • 581 B
JavaScript
import { createElement } from "./createElement"
export function cloneElement(vnode, props) {
let config, children;
for (let propName in vnode.props) {
if (propName === 'children') {
children = vnode.props[propName]
} else {
config[propName] = vnode.props[propName]
}
}
config = { ...config, ...props }
let newKey = props.key ? props.key : vnode.key
let newRef = props.ref ? props.ref : vnode.ref
config['key'] = newKey
config['ref'] = newRef
return createElement(vnode.type, config, children)
}