I am trying to display a list of buttons in a custom drawer component in React Native. The buttons successfully load and render, but immediately become "undefined" and are thus un-clickable. The specific error I am getting is " undefined is not an object (evaluating 'props.screenProps.data.menu.items') " when I click on the buttons. The app works fine before clicking on the buttons, and they are viewable.
I tried using some JS to only display the buttons if they are not undefined, but then the buttons just don't show up because they are undefined. My data is stored in redux.
My custom drawer:
const CustomDrawerComponent = (props) => (
<Provider store={store}>
<SafeAreaView style={{ flex: 1 }}>
<View style={{height: 150, backgroundColor: 'white', alignItems: 'center', justifyContent: 'center'}}>
<Text style={{marginTop: 50}}> Header Image / Logo</Text>
</View>
<ScrollView>
{ //props.screenProps shows my list of buttons correctly, but clicking on them gives
//the error of "undefined is not an object"
//after initially rendering, they switch immediately to undefined
//as proved by: '''(props.screenProps.data.menu.items == undefined) &&'''
//doesn't show any buttons in the drawer
props.screenProps.data.menu.items.map((_data) => { return( SideButtonClick(_data) ) })
}
</ScrollView>
</SafeAreaView>
</Provider>
)
const SideButtonClick = (data) => {
return(
<Button title={data.title} key={data.title}
onPress = {() => store.dispatch({
type: "CHANGE_CURRENT_DATA",
payload: data }) }
/>
);
}
edit: my reducers
export const reducer = (state = initialState, action) => {
switch (action.type) {
case "CHANGE_CURRENT_DATA": {
state = {
...state,
title: action.payload.title,
link: action.payload.link,
icon: action.payload.icon
};
console.log(action.payload);
}
case "CHANGE_DATA": {
state = {
...state,
data: action.payload
};
//console.log(action.payload);
}
}
return state;
};