Created
January 29, 2019 17:14
-
-
Save javedbaloch4/4bf21e09210563259df806379592de68 to your computer and use it in GitHub Desktop.
Simple toggle app using react with its states.
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 from 'react'; | |
const container = { width: '1000px', margin: '20px auto'} | |
class App extends React.Component { | |
constructor(props) { | |
super(props); | |
this.toggleVisibility = this.toggleVisibility.bind(this); | |
this.state = { | |
visiable: false | |
} | |
} | |
toggleVisibility() { | |
this.setState((prevState) => { | |
return { | |
visiable: !prevState.visiable | |
} | |
}) | |
} | |
render() { | |
return ( | |
<div style={container}> | |
<button onClick={this.toggleVisibility}> | |
{ this.state.visiable ? 'Hide Details' : 'Show Details' } | |
</button> | |
<p> | |
{ | |
this.state.visiable ? ' Here are some details about this post. ' : '' | |
} | |
</p> | |
</div> | |
) | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment