title: Keep getting 'map of undefined' when displaying table data, React hooks
body: <p>I'm trying to display years when the input is changed to 'years' using State, but I'm having an issue.</p>
  <pre><code>const handleChange = (e, countMonth,countYear) =&gt;{
  
        
    if(e.target.value === 'months'){
      setMonths(countMonth)
  
    } else if( e.target.value === 'year'){
      setMonths(countYear)
    
    }
  
  
  }
  </code></pre>
  <p>I'm trying to display different data when year is clicked with this map method:</p>
  <pre><code>      &lt;tbody&gt;
          {
            months.map(({ date, count }, index) =&gt; (
            &lt;tr key={index}&gt;
              &lt;td&gt;{date}&lt;/td&gt;
              &lt;td&gt;{count}&lt;/td&gt;
            &lt;/tr&gt;
          ))}
        &lt;/tbody&gt;
  </code></pre>
  <p>I keep getting the error <code>'TypeError: Cannot read property 'map' of undefined'</code></p>
  <p>Here is the full sandbox code: <a href="https://codesandbox.io/s/wizardly-clarke-szge3?file=/src/data.js" rel="nofollow noreferrer">https://codesandbox.io/s/wizardly-clarke-szge3?file=/src/data.js</a></p>