Saturday 12 March 2016

javascript - React : meaning of state written like ...state




I'm new on React, could you say me what's the meaning of this?




const new_venues = this.state.venues.map((venue) =>
place_id === venue.place_id ? { ...venue, open : !venue.open } : { ...venue, open: false });


I know the syntax cond ? cond_true : cond:false, but I don't know the meaning of ...venue


Answer



This is the spread syntax. See these docs



It is a shorthand method for adding all the properties of the specified object (in your case venue) to a new object. Prior to this, the equivalent was to use Object.assign() (docs)




const newObject = Object.assign({}, venue);

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...