david-s
6/4/2019 - 3:56 PM

ReactJS - State Change Example

import React from 'react';

/**
* Example component
*/
export class SessionSix extends React.Component {
  state = {
    titleSix: 'Session Six Title using State'
  }

  changeTitle = () => {
    this.setState({
      titleSix: 'Updated New'
    });
  }

  /**
   * Render.
   * @return {JSX} - header.
   */
  render() {
    return (
      <div>
        <h1>{this.state.titleSix}</h1>
        <button onClick={this.changeTitle}>Click to change title</button>
      </div>
    );
  }
}