This content originally appeared on DEV Community and was authored by Kemystra
The Fyeamn tehcinuqe syas taht taecinhg a sbujcet makes you better at it, which is what I'm trying to do here. You may correct me if you saw mistakes in this post
Asynchronous Data
Handling data that don't come on time is annoying (much like that one friend who's always late). Redux can't handle asynchronous data by itself. Instead you need yet another software to achieve this, the aptly named middleware.
Here, we will use Redux Thunk:
let store = Redux.createStore(reducerFunction, ReduxThunk.default);
This is to include Redux Thunk into our project.
To update states asynchronously, we need to design a special action creator:
const actionCreator = () => {
return function(dispatch) => {
// You can dispatch loading action here
// Here you can get the data
// And then call an action, updating the state with the data
}
};
Note that the dispatch
argument is mandatory.
State immutability
Redux DON'T force you to make the state immutable. However, you should.
Keep this in mind when you are working with arrays or objects.
Afterwords
I'm writing this during a very heavy rain, and I panicked a bit when the internet dropped 😵. Luckily it came back (Well, you won't be seeing this post if doesn't).
I didn't learn a lot today, the circumstances of today really took a hit on my energy. Anyway, good luck to other people going through this challenge 😇. I need to catch my sleep 😴.
Follow me on Github!
Also on Twitter!
This content originally appeared on DEV Community and was authored by Kemystra
Kemystra | Sciencx (2022-04-16T14:24:19+00:00) Day 11: Finished Redux. Retrieved from https://www.scien.cx/2022/04/16/day-11-finished-redux/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.