I am using a reducer to manage a varied of states on my application. But every time I add a new key to my initial state, like this:
const initialState = {
loading: false,
archiveTypes: [],
archiveType: {
id: null,
name: '',
local: '',
description: '',
}
}
The initialState never shows the new information until I dispatch some info to the reducer.
Is there a way to make it already start with all the information?
My full code:
import * as actionTypes from 'actions';
import produce from 'immer';
const initialState = {
loading: false,
archiveTypes: [],
archiveType: {
id: null,
name: '',
local: '',
description: '',
}
}
const archiveTypeReducer = produce((draft, action) => {
switch (action.type) {
case actionTypes.ARCHIVE_TYPE_GET_ALL_SUCCESS: {
draft.loading = false;
try {
draft.archiveTypes = action.payload
} catch (err) {
console.log(`REDUCER ERROR ${err}`)
}
return draft;
}
case actionTypes.ARCHIVE_TYPE_GET_BY_ID_SUCCESS: {
draft.loading = false;
try {
draft.archiveType = action.payload
} catch (err) {
console.log(`REDUCER ERROR ${err}`)
}
return draft;
}
case actionTypes.ARCHIVE_TYPE_REQUEST_FAILURE: {
draft = initialState
return draft
}
default: {
return draft;
}
}
}, initialState);
export default archiveTypeReducer;