Skip to content

Instantly share code, notes, and snippets.

@kpunith8
Last active September 15, 2018 07:44
Show Gist options
  • Save kpunith8/19f37302546cc04368fa79d9eaf2579c to your computer and use it in GitHub Desktop.
Save kpunith8/19f37302546cc04368fa79d9eaf2579c to your computer and use it in GitHub Desktop.
Fixing re-rendering of the links
import React, { Component } from 'react'
const sampleList = [{
name: 'Punith',
link: '[email protected]'
},
{
name: 'Rama',
link: '[email protected]'
}];
class App1 extends Component {
state = { isLinkClicked: false }
onLinkClicked = (event) => {
event.preventDefault();
this.setState({ isLinkClicked: !this.state.isLinkClicked })
}
render() {
return (
<div>
<ul style={{ fontSize: 30, listStyleType: 'none' }}>
{
sampleList.map(item =>
(<div key={item.name}>
<li><a href='' onClick={this.onLinkClicked}>{item.link}</a></li>
</div>)
)
}
</ul>
{this.state.isLinkClicked && <h1>Link clicked!</h1>}
</div>
)
}
}
export default App1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment