Oskar
Oskar

Reputation: 135

"SyntaxError: Unexpected token ..." in object literal

I've found this code in some tutorial. How does it work? Why isn't it working for me (I get SyntaxError: Unexpected token ...)?

const commentReducer = (state, action) => {
  return {
    ...state, //error on this line
    completed: !state.completed
  }
}

Upvotes: 2

Views: 1742

Answers (1)

Michał Perłakowski
Michał Perłakowski

Reputation: 92689

This code is using object spread properties, which are not a part of ECMAScript 6. They are currently an ECMAScript proposal at stage 3. To use them, you have to configure Babel to use stage-3 preset.

Upvotes: 4

Related Questions