Guest User

Untitled

a guest
Aug 21st, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import logo from './logo.svg';
  3. import './App.css';
  4.  
  5. export default class App extends Component {
  6. constructor() {
  7. super();
  8. this.state = {
  9. text: "Hello World",
  10. }
  11. this.changeText = this.changeText.bind(this);
  12. }
  13. changeText (){
  14. this.setState({
  15. text: this.state.text === "Hello World" ? "Hello Pakistan" : "Hello World",
  16. });
  17. }
  18. render() {
  19. return (
  20. <div className="App">
  21. <header className="App-header">
  22. <img src={logo} className="App-logo" alt="logo" />
  23. <h1 className="App-title" onClick={this.changeText}>{this.state.text}</h1>
  24. <p>Click the text to toggle the statement in the text</p>
  25. </header>
  26. </div>
  27. );
  28. }
  29. }
Add Comment
Please, Sign In to add comment