0

I was looking at some react code in my render method and I was wondering why 'this' is undefined ? I am using _this to reference this properly but I dont see why 'this' wouldn't work.

Here is the code:

 render: function(){
        var _this = this; 

        function message(){
            console.log('what is this ? ', this); // -> returns undefined!!!!

        }
        return(
            <div>
                <h3> Weather Component </h3>
                <WeatherForm onSearch={this.handleSearch}/> // This 'this' works fine
                {message()}
            </div>
        )
    }

I'm sure this is super easy. I just want to know why im getting undefined.

trebek1
  • 681
  • 1
  • 5
  • 23

0 Answers0