Problems of Context in Redux

Days ago here' a problem appeared when I use ` React context ' to finish some needs with ' Redux '.

React-Redux will cut off the link of the context between components.

At first , I need a state downs from father components to child components, it was worked very well , then when I finish the components work and turn to build containers with the library redux , my components working just now is like dead components.

And I check the context, the state was really in the components. It seems that I have any typing errors.

I just dizzy . because the Redux states come to components also by the context, but why my state can't.

** As customary, I add a function to log the state when the components update.
it works!
Remove the log function. it can't work.
This phenomenon made me associate the quantum mechanics . if being observed , it will work . **

Then I check the state, know that the state will not be updated if the components without any function touch it .

So ... Why is that?

** There just one possibility will be here which the state was optimized by the componentShouldUpdate . **

I think I know the problem really is .
the component connect comes from react-redux must have optimized the state by the componentShouldUpdate .
So I need to write a componentconnect without optimization.

Thus , I try to read the react-redux source code .
... after 1 minute ..I found out the solution .

export default connect(mapStateToProps, null, null, { pure: false })(Component);

I just need to add an object with a pure state to the connect.

Then everything has done.
Dan Abramov is my idol.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 11,110評(píng)論 0 23
  • 1 Introduction to evolutionary computation 1.1 Introducto...
    zhaohaoying閱讀 315評(píng)論 0 0
  • 記人生中的第一次兼職/在凌晨四點(diǎn)22分的時(shí)候醒過一次,生怕遲到,就這樣迷迷糊糊地睡到了六點(diǎn)鐘,然后就急急忙忙地...
    d5061534d9f4閱讀 275評(píng)論 0 0

友情鏈接更多精彩內(nèi)容