title: How to pass function with argument in classname field in React?
body: <p>I have following component in my React Project. What I want to do is to Add a className attribute to the <code>&lt;li&gt;</code> element. Set it equal to the return value of the getSortByClass() method and pass in sortByOptionValue as the argument. </p>
  
  <pre><code>import React from 'react';
  import './SearchBar.css';
  
  const sortByOptions = {
    'Best Match': 'best_match',
    'Highest Rated': 'rating',
    'Most Reviewed': 'review_count'
  }
  function getSortByClass(sortByOption){
    if (this.state.sortBy === sortByOption) {
      return 'active';
    }
    else {
      return '';
    }
  }
  function handleSortByChange(sortByOption){
    this.setState({
       sortBy: sortByOption
     });
  }
  export class SearchBar extends React.Component{
      renderSortByOptions(){
        return Object.keys(sortByOptions).map(sortByOption =&gt; {
          let sortByOptionValue = sortByOptions[sortByOption];
          return &lt;li className={getSortByClass(sortByOptionValue)} key={sortByOptionValue}&gt; {sortByOption} &lt;/li&gt;;
        });
      }
  
      constructor(props) {
          super(props);
          this.state = {
            term: '',
            location: '',
            sortBy: 'best_match',
          };
      }
      render(){
        return (
        &lt;div className="SearchBar"&gt;
          &lt;div className="SearchBar-sort-options"&gt;
            &lt;ul&gt;
              {this.renderSortByOptions()}
            &lt;/ul&gt;
          &lt;/div&gt;
          &lt;div className="SearchBar-fields"&gt;
            &lt;input placeholder="Search Businesses" /&gt;
            &lt;input placeholder="Where?" /&gt;
          &lt;/div&gt;
          &lt;div className="SearchBar-submit"&gt;
            &lt;a&gt;Lets Go&lt;/a&gt;
          &lt;/div&gt;
          &lt;/div&gt;
        );
      }
    }
  
    export default SearchBar;
  </code></pre>
  
  <p>I am getting error: <code>TypeError: Cannot read property 'state' of undefined</code> after setting the classname field.</p>