javascript - Define variable and return component from an arrow function -


i'd define variable inside .map() iteration, returning component.

but having variable inside map doesn't work (gives me error). possible @ all, , if how do this?

below simplified example of i'm trying do:

render() {   return(     <div>       {array.map( (element, index) => (         let disturbingvariable = 100 + index         <mycomponent disturbingvariable={disturbingvariable} />       ))}     </div>   ) } 

when arrow function has more 1 statement can no longer use implicit return syntax.

add block braces , return statement:

array.map((element, index) => {   let disturbingvariable = 100 + index   return <mycomponent disturbingvariable={disturbingvariable} /> }) 

alternatively, forgo variable declaration , perform addition in-place, maintaining implicit return:

array.map((element, index) =>   <mycomponent disturbingvariable={100 + index} />) 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -