I am getting a JSON object from firebase store in my redux action. I am storing the JSON objects inside an associative array. when I am trying to do this.props.expenses, I get back the array.
But I am not able to map the array in JSX??
import { SHOW_EXPENSE } from './types';
import database from '../config/firebase';
export const showExpenses = () => dispatch => {
const expenses = [];
database.ref()
.once('value')
.then((snapshot) => {
snapshot.forEach((childSnapshot) => {
expenses.push({
id: childSnapshot.key,
...childSnapshot.val()
})
});
});
console.log(expenses);
dispatch({
type: SHOW_EXPENSE,
expenses : expenses
})
return expenses;
};
This is my console.log(expenses);
0: {id: "-LUumVQzeXBN8iK81EVO", expense_amount: "500", expense_name:
"bike service"}
1: {id: "-LUumeeCeYIdd2G4Pz5K", expense_amount: "1500",
expense_name: "tire change"}
length: 2__proto__:
Array(0)
When I try to map this.props.expenses it returns nothing.
{this.props.expenses.map( data =>
{data.expense_amount}
{data.expense_name}
});