Last active
September 15, 2018 07:44
-
-
Save kpunith8/19f37302546cc04368fa79d9eaf2579c to your computer and use it in GitHub Desktop.
Fixing re-rendering of the links
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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