Skip to content

Instantly share code, notes, and snippets.

@javedbaloch4
Created January 29, 2019 17:14
Show Gist options
  • Save javedbaloch4/4bf21e09210563259df806379592de68 to your computer and use it in GitHub Desktop.
Save javedbaloch4/4bf21e09210563259df806379592de68 to your computer and use it in GitHub Desktop.
Simple toggle app using react with its states.
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