我有一个像下面(源)这样的组件层次结构,我的要求是,尽管渲染想将其转换为某些属性的Target
,这里我假设为flag
来源:
<Parent>
<Xyz flag={false}/>
<One flag={true}/>
<Two flag={true}/>
<Three flag={true}/>
</Parent>
目标:
<Parent>
<Xyz>
<One />
<Two />
<Three />
</Xyz>
</Parent>
我的方法:
父级
的侧面渲染render() {
const xyz = this.props.children.filter((children) => !children.props.flag);
const kids = this.props.children.filter((children) => children.props.flag);
const clonedXyz = React.cloneElement(xyz, [{...props}], [...kids]);
return(
<div>
{clonedXyz}
</div>
);
}
哪个抛出了预期的类/函数错误,但在React v15.x中得到了undefined
答案 0 :(得分:0)
得到答案https://codesandbox.io/s/7ww8n4my9x
应为microbenchmark::microbenchmark(
stringi = stri_join(rep("a",1000000),rep("b",1000),"c",sep=" "),
base = paste(rep("a",1000000),rep("b",1000),"c")
)
# Unit: milliseconds
# expr min lq mean median uq max neval cld
# stringi 88.54199 93.4477 97.31161 95.17157 96.8879 131.9737 100 a
# base 166.01024 169.7189 178.31065 171.30910 176.3055 215.5982 100 b