栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

为什么不赞成使用变异样式?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

为什么不赞成使用变异样式?

查看测试用例/预期的错误,您是正确的,应该克隆对象。

Warning: `div` was passed a style object that has previously beenmutated. Mutating `style` is deprecated. Consider cloning itbeforehand. Check the `render` of `App`. Previous style:{border: "1px solid black"}. Mutated style:{border: "1px solid black", position: "absolute"}.

https://github.com/facebook/react/blob/fc96f31fade8043856eb7bc34c56598c4a576110/src/renderers/dom/shared/
测试 /ReactDOMComponent-
test.js#L128

我想这与道具的推理类似-它使您免于在任何地方传递可变样式对象,并最终失去了React真正擅长为您提供帮助的大量推理功能。

The props object is now frozen, so mutating props after creating a componentelement is no longer supported. In most cases, React.cloneElement should beused instead. This change makes your components easier to reason about andenables the compiler optimizations mentioned above.



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/378919.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号