title: TypeError: Cannot read property 'length' of undefined, API TMDB
body: <p>I am using the TMDB API which allows me to display movies in a list.</p>
  <p>I have my Add.js component which allows me to make a query and search for the movies and add them to my list</p>
  <p>But I get this error:</p>
  <blockquote>
  <p>TypeError: Cannot read property 'length' of undefined</p>
  </blockquote>
  <p><strong>Add.js</strong></p>
  <pre><code>import React, { useState } from &quot;react&quot;;
  import { ResultCard } from &quot;./ResultCard&quot;;
  
  export const Add = () =&gt; {
    const [query, setQuery] = useState(&quot;&quot;);
    const [results, setResults] = useState([]);
  
    const onChange = (e) =&gt; {
      e.preventDefault();
  
      setQuery(e.target.value);
  
      fetch(
        `https://api.themoviedb.org/3/search/movie?api_key=${process.env.REACT_APP_TMDB_KEY}&amp;language=en-US&amp;page=1&amp;include_adult=false&amp;query=${e.target.value}`
      )
        .then((res) =&gt; res.json())
        .then((data) =&gt; {
          if (!data.errors) {
            setResults(data.results);
          } else {
            setResults([]);
          }
        });
    };
  
    return (
      &lt;div className=&quot;add-page&quot;&gt;
        &lt;div className=&quot;container&quot;&gt;
          &lt;div className=&quot;add-content&quot;&gt;
            &lt;div className=&quot;input-wrapper&quot;&gt;
              &lt;input
                type=&quot;text&quot;
                placeholder=&quot;Search for a movie&quot;
                value={query}
                onChange={onChange}
              /&gt;
            &lt;/div&gt;
  
            {results.length &gt; 0 &amp;&amp; (
              &lt;ul className=&quot;results&quot;&gt;
                {results.map((movie) =&gt; (
                  &lt;li key={movie.id}&gt;
                    &lt;ResultCard movie={movie} /&gt;
                  &lt;/li&gt;
                ))}
              &lt;/ul&gt;
            )}
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    );
  };
  </code></pre>