When data is received at browser, isLoading state will be returned as false in ‘ITEMS_REQUEST_SUCCESS’ action type in the corresponding reducer. Initially, the isLoading state was false in the initialState object assuming nothing is loading. Meanwhile, the isLoading state is made true in the reducer in ‘ITEMS_REQUEST’ action type to indicate that items are loading, and data is still not received from the server. Let us learn about action creator which lets you dispatch an action, ‘ITEMS_REQUEST’ that requests for the product items list data from the server. It promotes writing clean code and helps to achieve reusability. These functions simply return a plain Js object which is an action. The action object is as follows −Īction creators are the functions that encapsulate the process of creation of an action object. To cause any change in the store, you need to dispatch an action first by using store.dispatch() function. It is recommended to keep your action object as light as possible and pass only the necessary information. Types should be defined as string constants in your application as given below −Īpart from this type attribute, the structure of an action object is totally up to the developer. It carries a payload of information from your application to store.Īs discussed earlier, actions are plain JavaScript object that must have a type attribute to indicate the type of action performed. Actions are the only source of information for the store as per Redux official documentation.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |