react 对象动态添加属性 setState

react 对象动态添加属性 setState,第1张

一个标志,表示其为一个React Element, 源码如下,有英文解释

// The Symbol used to tag the ReactElement type. If there is no native Symbol

// nor polyfill, then a plain number is used for performance.

var REACT_ELEMENT_TYPE =

(typeof Symbol === 'function' &&Symbol.for &&Symbol.for('react.element')) ||

0xeac7

var ReactElement = function(type, key, ref, self, source, owner, props) {

var element = {

// This tag allow us to uniquely identify this as a React Element

$$typeof: REACT_ELEMENT_TYPE,

// Built-in properties that belong on the element

type: type,

key: key,

ref: ref,

props: props,

// Record the component responsible for creating this element.

_owner: owner,

}

.....

}

补充一下,它存在的作用。

有加这个$$typeof之前,object被认为是有效的React Element。为了将React Element和普通的对象区分开,

判断React的children是否是一个React Element, 来尽可能防止xss漏洞。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11603202.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存