W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
在極少數(shù)應(yīng)用場景中,一個(gè)組件可能想改變另一個(gè)它不擁有的組件的props(就像改變一個(gè)組件的className
,這個(gè)組件又作為this.props.children
傳入)。其它的時(shí)候,可能想生成傳進(jìn)來的一個(gè)組件的多個(gè)拷貝。cloneWithProps()
使其成為可能。
ReactComponent React.addons.cloneWithProps(ReactComponent component, object? extraProps)
做一個(gè)component
的淺復(fù)制,合并extraProps
提供的每一個(gè)props。className
和style
props將會(huì)被智能合并。
注意:
cloneWithProps
并不傳遞key
到克隆的組件中。如果你希望保留key,將其添加到extraProps
對象:var clonedComponent = cloneWithProps(originalComponent, { key : originalComponent.key });
ref
也一樣不會(huì)保留。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: