我正在学习react redux,我使用firebase
来存储数据。
我安装了thunk中间件。一切正常,我只是不明白为什么。
据我了解,const费用是另一个功能范围内的对象。 addExpense
如何访问它?
export const addExpense = (expense) => ({
type: 'ADD_EXPENSE',
expense
});
export const startAddExpense = (expenseData = {}) => {
return (dispatch) => {
const {
description = '',
note = '',
amount = 0,
createdAt = 0
} = expenseData;
const expense = { description, note, amount, createdAt };
database.ref('expenses').push(expense).then((ref) => {
dispatch(addExpense({
id: ref.key,
...expense
}));
});
};
};
答案 0 :(得分:1)
startAddExpense
正在将const expense
对象与addExpense
字段一起传递给您的id
字段。恰好,addExpense
的参数也称为expense
,这可能会让您感到困惑。
希望能够解决它。