[英]Why I shouldn't use toJS() in React Redux? (mapStateToProps)
I've just read it on Redux's docs, that I shouldn't really use Immutable with Redux. 我刚刚在Redux的文档中阅读了它,我不应该真正在Redux中使用Immutable。 I just can't my head around this thing.
我只是无法解决这个问题。 Why I shouldn't use toJS() in the mapStateToProps?
为什么我不应该在mapStateToProps中使用toJS()? I mean React is using Deep Compare, AND I didn't had any re-render problem with it yet.
我的意思是React正在使用Deep Compare,并且我还没有任何重新渲染问题。 (I just logging on render to see if is there any leak.)
(我只是登录渲染器,看是否有泄漏。)
Why I shouldn't use toJS() in the mapStateToProps
为什么我不应该在mapStateToProps中使用toJS()
You shouldn't use toJS()
in mapStateToProps
because toJS()
returns a new object reference and even though connect
is pure(ie it does shallow comparison), it may so happen that its returns a false negative when the object is nested and in this case your component will re-render ie the render
function will be called and react will have to run the diffing algorithm which will have a performance impact as the size of your App goes. 您不应该在
mapStateToProps
使用toJS()
,因为toJS()
返回一个新的对象引用,即使connect
是纯函数(即,它进行了浅层比较),也可能发生这样的情况:当嵌套对象并在其中插入对象时,它返回false否定值在这种情况下,您的组件将重新渲染,即,将调用render
函数,并且react必须运行diffing算法,这将对应用程序的大小产生性能影响。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.