React State

Initializing State

Ex:

import React from 'react';

class RandomQuote extends React.Component {
  constructor() {
    super();

    const quote = 'May the Force be with you.';

    this.state = { 
      quote: quote 
    };
  }

  render() {
    return (
      <>
        <h2>Random Quote</h2>
        <p>{this.state.quote}</p>
      </>
    );
  }
}

Updating State

Ex:

changeQuote = () => {
  const newQuote= 'My favorite state is non-Newtonian fluid.'

  this.setState({ 
    quote: newQuote 
  });
}