title: Onclick event not changing this.state.value2 variable
body: <p>when the weather details are displayed after search, clicking on the image is supposed to append the details and display the retVal in the handleClick event. For some reason this.setState for value2 is not even changing the variable and keeping it null.Ive tried converting to async thinking that maybe setState hadnt been finished by the time the page rendered but that didnt work either.</p>
  <pre><code>class Search extends React.Component {
    constructor(props) {
      super(props);
      this.state = {
        city: &quot;&quot;,
        temp: 0,
        feels: &quot;&quot;,
        w_status: &quot;&quot;,
        description: &quot;&quot;,
        condition: &quot;&quot;,
        max: 0,
        min: 0,
        wind_speed: 0,
        humidity: &quot;&quot;,
        pressure: 0,
        sunrise: 0,
        lastUpdate: &quot;&quot;,
        image: &quot;&quot;,
  
        value1: null,
        value2: &quot;Value 2 is currently null&quot;,
        activate_err: false,
  
      };
  
      this.handleClick = this.handleClick.bind(this);
      this.handleSubmit = this.handleSubmit.bind(this);
    }
  
   handleClick(e) {
        console.log(&quot;handle click is being called&quot;);
      const retval = (
        &lt;div&gt;
          &lt;p&gt;Maximum Temprature: {this.state.max}&lt;/p&gt;
          &lt;p&gt;Minimum Temprature: {this.state.min}&lt;/p&gt;
          &lt;p&gt;Humidity: {this.state.humidity}&lt;/p&gt;
          &lt;p&gt;Wind Speed: {this.state.wind_speed}&lt;/p&gt;
          &lt;p&gt;Pressure: {this.state.pressure}&lt;/p&gt;
          &lt;p&gt;Sunrise: {this.state.sunrise}&lt;/p&gt;
        &lt;/div&gt;
      );
  
  
      
      if(this.state.value2 != null){
        this.setState({ value2: null});
        console.log(&quot;It is hidden&quot;);
      }
      else{
        this.setState({ value2: retval});
          console.log(&quot;It is shown&quot;);
  
      }
  
    }
    async handleSubmit(e) {
      const search = e.target.SearchVal.value;
      console.log(&quot;You entered &quot; + search);
      console.log(&quot;Time to modify the entry!&quot;);
      e.preventDefault();
  
      //Converts any string with extra spaces to one space in between
      console.log(search.replace(/\s{2,}/g, &quot; &quot;).trim());
  
      const results = search
        .replace(/\s{2,}/g, &quot; &quot;)
        .trim()
        .split(&quot; &quot;);
  
      await fetch(
        &quot;https://api.openweathermap.org/data/2.5/weather?q=&quot; +
          results +
          &quot;&amp;appid=&quot; +
          KEY
      )
        .then((response) =&gt; response.json())
        .then((data) =&gt; {
          console.log(data);
          if (data[&quot;cod&quot;] != 200) {
            console.log(
              &quot;Error during search, activate err has been set to true!&quot;
            );
            this.setState({ activate_err: true });
          } else {
            this.setState({
              city: data[&quot;name&quot;],
              temp: data[&quot;main&quot;][&quot;temp&quot;],
              feels: data[&quot;main&quot;][&quot;feels_like&quot;],
              w_status: data[&quot;weather&quot;][0][&quot;main&quot;],
              description: data[&quot;weather&quot;][0][&quot;description&quot;],
              max: data[&quot;main&quot;][&quot;temp_max&quot;],
              min: data[&quot;main&quot;][&quot;temp_min&quot;],
              wind_speed: data[&quot;wind&quot;][&quot;speed&quot;],
              humidity: data[&quot;main&quot;][&quot;humidity&quot;],
              pressure: data[&quot;main&quot;][&quot;pressure&quot;],
              sunrise: data[&quot;sys&quot;][&quot;sunrise&quot;],
              image:
                &quot;http://openweathermap.org/img/wn/&quot; +
                data[&quot;weather&quot;][0][&quot;icon&quot;] +
                &quot;@2x.png&quot;,
              activate_err: true,
            });
  
            const retval = (
              &lt;div&gt;
                &lt;hr /&gt;
                &lt;div  className=&quot;weather-card&quot;&gt;
                  &lt;h3&gt;City: {this.state.city}&lt;/h3&gt; &lt;img onClick={() =&gt; this.handleClick()} src={this.state.image} /&gt;
                  &lt;h3&gt;
                    Temprature: {this.state.temp} Feels Like: {this.state.feels}
                  &lt;/h3&gt;
                  &lt;p&gt;{this.state.w_status}&lt;/p&gt;
                  &lt;p&gt;{this.state.description}&lt;/p&gt;
                  &lt;div id=&quot;details&quot; className=&quot;weather-details&quot;&gt;
                    {this.state.value2}
                  &lt;/div&gt;
                &lt;/div&gt;
                &lt;hr /&gt;
              &lt;/div&gt;
            );
  
            this.setState({ value1: retval });
          }
        })
        .catch((err) =&gt; {
          console.log(err);
        });
  
      if (this.state.activate_err == false) {
      }
  
      /*
          let status = true;
          let activate = false;
          let i = 0;
  
          while(status){
              
              if(result[i] == ' ')
              status = false;
              if(activate){
  
              }
          }
  
          status = true;
  */
    }
    render() {
      return (
        &lt;div&gt;
          &lt;form onSubmit={this.handleSubmit}&gt;
            &lt;input
              type=&quot;search&quot;
              placeholder=&quot;Enter a city, country or country code!&quot;
              name=&quot;SearchVal&quot;
            /&gt;
            &lt;input type=&quot;submit&quot; value=&quot;Search&quot; /&gt;
          &lt;/form&gt;
  
  
          &lt;div id=&quot;search-results&quot;&gt;{this.state.value1}&lt;/div&gt;
        &lt;/div&gt;
      );
    }
  }
  
  </code></pre>