Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redux action creator syntax

function addTodoWithDispatch(text) {
  const action = {
    type: ADD_TODO,
    text
  }
  dispatch(action)
}

http://redux.js.org/docs/basics/Actions.html#action-creators

I saw the code above from redux documentation. What I don't understand is the text in the action. It doesn't look like a valid javascript object or array syntax. Is it an ES6 new syntax? Thanks.


1 Answers

It is just a new ES6 syntax, which simplifies creating properties on the literal syntax

In short, if the name is the same as the property, you only have to write it once

So this would be exactly the same :)

function addTodoWithDispatch(text) {
  const action = {
    type: ADD_TODO,
    text: text
  }
  dispatch(action)
}
like image 100
Icepickle Avatar answered Dec 01 '25 12:12

Icepickle