javascript - braces around params -- why? -


this question has answer here:

i ran across in tutorial:

const todos = ({todos}) => (   <div>     <h1>todos</h1>     {todos.map(todo => <p key={todo}>{todo}</p>)}   </div> ) 

why parameter have braces around it? if i'd written myself, first line this:

const todos = (todos) => (... 

is wacky new es6 syntax can't find documented?

this syntax parameter object destructuring, introduced part of ecmascript 2015. todos function doesn't define single parameter named todos, instead accesses todos property of object that's passed in (and destructured).

it equivalent following version:

const todos = (_param) => {   let todos = _param.todos;   return (     <div>       <h1>todos</h1>       {todos.map(todo => <p key={todo}>{todo}</p>)}     </div>   ); }; 

check out destructuring , parameter handling more information on destructuring.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -