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)容合作請聯(lián)系作者
  • 序言:七十年代末叼架,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖李请,帶你破解...
    沈念sama閱讀 221,273評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件毫玖,死亡現(xiàn)場離奇詭異,居然都是意外死亡叠艳,警方通過查閱死者的電腦和手機(jī)烁登,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,349評論 3 398
  • 文/潘曉璐 我一進(jìn)店門怯屉,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人饵沧,你說我怎么就攤上這事锨络。” “怎么了捷泞?”我有些...
    開封第一講書人閱讀 167,709評論 0 360
  • 文/不壞的土叔 我叫張陵足删,是天一觀的道長寿谴。 經(jīng)常有香客問我锁右,道長,這世上最難降的妖魔是什么讶泰? 我笑而不...
    開封第一講書人閱讀 59,520評論 1 296
  • 正文 為了忘掉前任咏瑟,我火速辦了婚禮,結(jié)果婚禮上痪署,老公的妹妹穿的比我還像新娘码泞。我一直安慰自己,他們只是感情好狼犯,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,515評論 6 397
  • 文/花漫 我一把揭開白布余寥。 她就那樣靜靜地躺著,像睡著了一般悯森。 火紅的嫁衣襯著肌膚如雪宋舷。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,158評論 1 308
  • 那天瓢姻,我揣著相機(jī)與錄音祝蝠,去河邊找鬼。 笑死幻碱,一個(gè)胖子當(dāng)著我的面吹牛绎狭,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播褥傍,決...
    沈念sama閱讀 40,755評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼儡嘶,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了恍风?” 一聲冷哼從身側(cè)響起社付,我...
    開封第一講書人閱讀 39,660評論 0 276
  • 序言:老撾萬榮一對情侶失蹤承疲,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后鸥咖,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體燕鸽,經(jīng)...
    沈念sama閱讀 46,203評論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,287評論 3 340
  • 正文 我和宋清朗相戀三年啼辣,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了啊研。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,427評論 1 352
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡鸥拧,死狀恐怖党远,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情富弦,我是刑警寧澤沟娱,帶...
    沈念sama閱讀 36,122評論 5 349
  • 正文 年R本政府宣布,位于F島的核電站腕柜,受9級特大地震影響济似,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜盏缤,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,801評論 3 333
  • 文/蒙蒙 一砰蠢、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧唉铜,春花似錦台舱、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,272評論 0 23
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至灰嫉,卻和暖如春拆宛,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背熬甫。 一陣腳步聲響...
    開封第一講書人閱讀 33,393評論 1 272
  • 我被黑心中介騙來泰國打工胰挑, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人椿肩。 一個(gè)月前我還...
    沈念sama閱讀 48,808評論 3 376
  • 正文 我出身青樓瞻颂,卻偏偏與公主長得像,于是被迫代替她去往敵國和親郑象。 傳聞我的和親對象是個(gè)殘疾皇子贡这,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,440評論 2 359

推薦閱讀更多精彩內(nèi)容

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