Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redux action.type gives @@redux/INIT

Tags:

reactjs

redux

My reducer file is as follows.

import { AppConstants } from '../constants';

const initialState = {
  state: [],
  menu_items: [],
  addon_items: [],
  save_items: [],
  un_mapped_menu_items: false,
  error: ''
};

export default (state = initialState, action) => {
 switch (action.type) {
   case AppConstants.getMenuItems:
    return {
     ...state,
   }
   case AppConstants.getMenuItemsSuccess:
    return {
     ...state,
     menu_items: action.menu_items
    }
   case AppConstants.getAddonsItems:
    return {
     ...state,
   }
   case AppConstants.getAddonsItemsSuccess:
    return {
    ...state,
    addon_items: action.addon_items
   }
   case AppConstants.getMenuItemsEdit:
    return {
    ...state,
   }
   case AppConstants.getMenuItemsSave:
    return {
    ...state,
    save_items: action.save_items
   }
   case AppConstants.getUnmappedMenuItems:
    return {
    ...state,
    error: action.error,
    un_mapped_menu_items: true
   }
  case AppConstants.getMenuItemsError:
    return {
    ...state,
    error: action.error
   }
  default:
  return state
  }
 };

When I debug my reducer file the action.type shows '@@redux/INIT'. I do not understand this . why does this gives this? My action file gives correct data when debugging it. How do I remove this error?

like image 371
sugandh_g Avatar asked Jan 30 '23 00:01

sugandh_g


1 Answers

When a store is created an @@redux/INIT action is dispatched by createStore

From the Code:

export var ActionTypes = {
  INIT: '@@redux/INIT'
}

  // When a store is created, an "INIT" action is dispatched so that every
  // reducer returns their initial state. This effectively populates
  // the initial state tree.
  dispatch({ type: ActionTypes.INIT })

See the code here: https://github.com/reactjs/redux/blob/v3.0.6/src/createStore.js

like image 150
Shubham Khatri Avatar answered Feb 03 '23 19:02

Shubham Khatri