简体   繁体   中英

Arrow function passing a variable within a prop within a .map

I am trying to pass a variable to a prop function in React that is all within a .map function.

I am getting an Invalid Left-Hand Side in arrow function parameters error.

<div style={ style.navContainer }>
    {navItems.map((item, i) => <div key={ i } onClick={ (item.name) => this.props.onClickGoTo(name) } style={ style.navItem }>
                <img style={ style.icon } src={ item.src } />
                { item.name }</div>)}
</div>

Almost. It should be:

onClick={ () => this.props.onClickGoTo(item.name) }

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM