javascript - Function declaration of ES6 syntax -


this question has answer here:

suppose have function using es6 syntax this:

const accountoverview = (props) => {   const overviewvisible = props.overviewvisible;   const accountnumber = props.accountnumber;   const toggleaccountoverview = props.toggleaccountoverview;    const onclick = (e) => {     e.preventdefault();     toggleaccountoverview(!overviewvisible, accountnumber);   };   // fixme: eslint why??????   /* eslint-disable */   return (     <div       classname={props.overviewvisible ? 'acc-block open' : 'acc-block'}     >         <div> ) } 

and function this:

const accountdetails = props => (   <div classname="tabinner">           </div> ) 

why first function declared using {} , second function declared using ()?

{} means body of arrow function, can contain multiple statements. in case need use return explicitly return data function.

without {}, arrow function must have single statement body result returned implicitly without return statement.

the () in situations need return object within single statement body. like

const getobject = () => ({ name: 'test' }); 

without () consider {} of object function body , give error.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -