I am wondering if there is an easier way to use a nested "this" in a Stencil.js component.
At the moment I am doing this:
render() {
let thisNested = this;
return <Host>
{this.images ?
this.imagesArray.map(function (el) {
return <img
// @ts-ignore
src={thisNested.imageSize ? thisNested.imageSize : el.url}/>
}) : <slot/>}
</div>
</Host>;
}
But I am always repeating myself writing a nested this variable as seen above.
Is there a more elegant way to do what I need?
Use arrow function:
render() { return <Host> {this.images? this.imagesArray.map((el) => (<img // @ts-ignore src={this.imageSize || el.url}/> )): <slot/>} </div> </Host>; }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.