0
export const startAddExpense = () => {
  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(ref.key, ...expense));
    })
  }
}

export class AddExpensePage extends React.Component {
  onSubmit = (expense) => {
    this.props.startAddExpense(expense);
    this.props.history.push('/');
  };
  render() {
    return (
      <div>
        <h1>Add Expense</h1>
        <ExpenseForm
          onSubmit={this.onSubmit}
        />
      </div>
    );
  }
}

I don't know what expenseData is. Why is the equal sign on the right?

What does the code say?

John Ruddell
  • 25,283
  • 6
  • 57
  • 86
TIMEX
  • 259,804
  • 351
  • 777
  • 1,080

1 Answers1

4

This is called destructuring assignment syntax which was introduced in es6. It is a way to pluck values from an existing variable

const foo = { bar: 0, baz: 1 } 
const { bar } = foo
console.log(bar) // 0

the older way to write this would be

var foo = { bar: 0, baz: 1 } 
var bar = foo.bar
console.log(bar) // 0
John Ruddell
  • 25,283
  • 6
  • 57
  • 86