Home > database >  React and Redux : How to show the action.type on the Components?
React and Redux : How to show the action.type on the Components?

Time:02-02

i want to be able to show status of the action.type in the component when i trigger it : it's for showing if an action has been passed succesfully or not(when catch triggered). Have you an idea please ?

CodePudding user response:

*emphasized text*someAction.js
when a action will be called dispatch the follwing line. 



    const someActionToBeCalledFromComponent = (parameters) => async(dispatch) => {
      try {
        dispatch({
          type: SOME_ACTION_HAS_CALLED_SUCCESSFULLY
        });
        //do your stufs 
      } catch (error) {
        //do your stufs
      }
    }

    <!-- begin snippet: js hide: false console: true babel: false -->
}) //do your stuffs . } catch(error) { //do your stufs here. } } <!-- end snippet --> Now in reducer catch the action type
    const someReducer = (state, action) => {
        switch (action.type) {

          case: SOME_ACTION_HAS_CALLED_SUCCESSFULLY
          return {
            status_of_the_action_type: true
          }

          //other cases goes here
          default: return state
        }
Now keep the reducer in a state and use it in typical way of redux.

CodePudding user response:

If you want to access it through your console :

If you have access to the action inside your component,

you could simply trigger a console.log(action.type) inside it.

  •  Tags:  
  • Related