React: problems with …spreading

React: problems with …spreading



I'm trying to recreate the Redux example from Dan Abramov's course. Spreading the ...store.getState() at App level does not work, Redux is changing the state and React does not re-render.


...store.getState()



When I replace line 121 with line 123, the code throws an error.



Full code is here: https://github.com/asaadsaad/redux-react-code/blob/master/13-redux.html



State object:
todos: [id, text, completed], visivility: 'ALL'


todos: [id, text, completed], visivility: 'ALL'



This line works fine:
<TodoApp todos=store.getState().todos visibility=store.getState().visivility />


<TodoApp todos=store.getState().todos visibility=store.getState().visivility />



This line does not work:
<TodoApp ...store.getState() />


<TodoApp ...store.getState() />



Why is this happening?




1 Answer
1



You have a typo in your combineReducer's part:


combineReducer


const appReducer = combineReducers(
todos: todos_reducer,
visivility: visibility_reducer
)



Change it to: visivility -> visibility


visivility -> visibility



So, why this works with the original one? See:


visibility=store.getState().visivility



Here, you are passing store.getState().visivility state as visibility to your App. Typo fixed here by luck. But when you spread the object visivility goes as it is.


store.getState().visivility


visibility


visivility





Thanks a lot.. It happens after 10 hours of reading and coding..
– Asaad Saad
Aug 30 at 2:29





You are welcome. It happens all the time. Sometimes we need a break :) By the way, just try to follow the data like this kind of situation. At first, I did not see the typo. With a couple of console.log I see that actually the code can add a todo to the store then figure out visibility is undefined in the TodosList component. The rest was easy.
– devserkan
Aug 30 at 2:33


console.log


todo


visibility


TodosList





Appreciate it.. Thanks.
– Asaad Saad
Aug 30 at 2:36



Required, but never shown



Required, but never shown






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế