logo

什么是 React.cloneElement?它与 this.props.children 有什么区别?

What is React.cloneElement? And the difference with this.props.children?

题目类型: 技术面试题

这是一道技术面试题,常见于澳洲IT公司面试中。

难度: hard

分类: Frontend

标签: cloneElement, children, ref

参考答案摘要

答案 React.cloneElement 会基于传入的 element 克隆并返回一个新的 React element。新 element 会保留原 element 的 props,并把新的 props 以浅合并(shallowly merged)的方式合并进去。新的 children 会替换已有的 children。原 element 的 key 和 ref 会被保留。 React.clone...

本题提供 STAR 原则详细解答和技术解析,登录匠人学院学习中心即可查看完整答案。

← 返回面试题库

什么是 React.cloneElement?它与 this.props.children 有什么区别?

Hardreactjavascript

想查看完整答案?

登录匠人学院学习中心,获取 STAR 格式回答和详细技术解析

前往学习中心查看答案