I know it’s been a while, but I didn’t realize how long it had been since the last time I made some changes to my blog here.
So many things have changed but I will write about that in another post. This is one is in regards to Redux.
Just a quick update I have decided to learn React Native. I’ve been at it for about a month just a few days short and everything was going great until (sinister music would be playing about now, it is in my head).
I think the problem started when I didn’t quite understand the purpose behind it, why we should use it and how it would help. Instead I just kept on reading and watching and becoming more and more confused.
I was blindly following along with the tutorial and I had to stop myself. I had one of those serious talks with myself and decided I had to go back and try again. Pause what I was doing and rewind.
So here I am going back to what works for me and that is to try and explain it to others so that I can better understand it myself.
Let’s get started with what is Redux.
This collector bin is called a store, (good name because it helps to think of it as a store where all the components have to come and get their state from the store). Redux makes this even easier by using Redux.createStore() to create a store.
store.dispatch() will send the action creator to the store.
Well now the store needs to be told what to do with that action. In comes the reducer function. The reducer is how we make modifications to the state based on an action. However a reducer must not make changes to the original state. It will take the state and create a new version of it and return the new version. The reducer is simply a pure function that takes state and action, then returns new state.
The way the reducer works is like a giant if statement. If what you received matches a specific action do this with the state and send it back. If the user logged in change the homepage to their set up. If they clicked the new account button take them to the sign up component, etc.. You can tell the Redux store how to handle multiple action types.
This is pretty much the basics behind Redux. You use it to keep state in one location for easier access.
Let me know what you think.