Created
May 28, 2018 19:06
-
-
Save JackHowa/c6aa2b5708e086cbd81080c9f675cadb to your computer and use it in GitHub Desktop.
react fcc beta code snippets
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
// React - Bind 'this' to a Class Method | |
class MyComponent extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
visibility: false | |
}; | |
// change code below this line | |
this.toggleVisibility = this.toggleVisibility.bind(this) | |
// change code above this line | |
} | |
// change code below this line | |
toggleVisibility() { | |
this.setState({ | |
visibility: !(this.state.visibility) | |
}) | |
} | |
// change code above this line | |
render() { | |
if (this.state.visibility) { | |
return ( | |
<div> | |
<button onClick={this.toggleVisibility}>Click Me</button> | |
<h1>Now you see me!</h1> | |
</div> | |
); | |
} else { | |
return ( | |
<div> | |
<button onClick={this.toggleVisibility}>Click Me</button> | |
</div> | |
); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://learn.freecodecamp.org/front-end-libraries/react/render-react-on-the-server-with-rendertostring
<App />