The inner function receives the store methods dispatch and getState as parameters. The thunk can be used to delay the dispatch of an action or to dispatch only if a certain condition is met. It allows you to write action creators that return a function instead of an action. Redux Thunk is a middleware for Redux which, as I mentioned, can enable redux to handle asynchronous operations. And that is where redux-thunk comes into the picture. We need something which can enable redux to handle asynchronous operations besides having synchronous ones. Why? Because all Redux does is dispatching an action to the reducer synchronously to alter the store. This is when the asynchronous nature of the application comes into play and only using Redux would no longer work. Meaning, you would create the todo on the server first and then alter the application state based on the response. But imagine, one day you want to synchronize all the todos on the server. This is all fine until you’re doing all these operations on the client-side only. Import React from ' react ' import The problem So, if we were to make a Todo app, you can do it by using createStore() like so.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |