Skip to content

Commit

Permalink
Convert Visibility Toggle to Components
Browse files Browse the repository at this point in the history
  • Loading branch information
jchlu committed Nov 26, 2017
1 parent fe6f664 commit e8be172
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
39 changes: 38 additions & 1 deletion src/playground/build-it-visible.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
import ReactDOM from 'react-dom'
class VisibilityToggle extends React.Component {
constructor (props) {
super(props)
this.handleToggleVisibility = this.handleToggleVisibility.bind(this)
this.buttonShowText = 'Show Details'
this.buttonHideText = 'Hide Details'
this.title = 'Visibility App'
this.subTitle = 'Extra details to be show on toggle'
this.state = {
visibility: false
}
}

handleToggleVisibility () {
this.setState((previousState) => {
return {
visibility: !previousState.visibility
}
})
}

render () {
return (
<div>
<h1>{this.title}</h1>
<button onClick={this.handleToggleVisibility}>
{this.state.visibility
? this.buttonHideText
: this.buttonShowText}
</button>
{this.state.visibility && <div><p>{this.subTitle}</p></div>}
</div>
)
}
}

ReactDOM.render(<VisibilityToggle />, document.getElementById('app'))
/*
const appRoot = document.getElementById('app')
const app = {
Expand Down Expand Up @@ -29,3 +65,4 @@ const renderApp = () => {
}
renderApp()
*/
2 changes: 1 addition & 1 deletion src/playground/counter-and-previous-wip.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Counter extends React.Component {
addOne () {
// Passing setState a function is the preferred way now & in the future.
// The "old way" of passing in the changes causes asyncronous bugs and
// will likelt be deprecated in future versions
// will likely be deprecated in future versions
this.setState((previousState) => {
return {
count: previousState.count + 1
Expand Down

0 comments on commit e8be172

Please sign in to comment.