I would like to save object data inside my array state. But when I try to call an action in reducer, the INITIAL_STATE.highlightedVerse always resulted as undefined when I tried to console.log() it. It should be an empty array, not undefined.
These are the dependencies that I used in package.json Expo v32.0.0, React v16.5.0, Redux v4.0.1, React Redux v5.1.1, Redux Persist v.5.10.0
These are the code that I wrote:
import {
ADD_BIBLE_VERSE_HIGHLIGHT,
REMOVE_BIBLE_VERSE_HIGHLIGHT,
} from 'ndc-ministry/redux/actions/types'
const INITIAL_STATE = {
highlightedVerse: [],
}
const reducer = (state = INITIAL_STATE, action) => {
switch (action.type) {
case ADD_BIBLE_VERSE_HIGHLIGHT:
const currentHighlightedVerse = state.highlightedVerse
if(currentHighlightedVerse.length > 0){
currentHighlightedVerse.forEach(obj => {
if(action.payload.bookIndex == obj.bookIndex
&& action.payload.chapterIndex == obj.chapterIndex
&& action.payload.verseIndex == obj.verseIndex
) {
return {...state}
}
})
}
return {
...state,
highlightedVerse: [...state.highlightedVerse, action.payload]
}
case REMOVE_BIBLE_VERSE_HIGHLIGHT:
const deletedHighlightVerse = state.highlightedVerse.filter(obj => JSON.stringify(action.payload) != JSON.stringify(obj))
return {
...state,
highlightedVerse: deletedHighlightVerse
}
default:
return state
}
}
export default reducer
In development mode, it works just fine. But when I updated it to production APK/IPA, it always returns undefined and I have no idea how. I already tried to search for two days but still could not understand why.
Thank you for reading this issue and I hope someone could help me on this :)