title: TypeError: Cannot read properties of null (reading 'user')
body: <p>I want to get (mohammad) in my console but when I use: console.log(user.user.name), I give TypeError: Cannot read properties of null (reading 'user')  !
  why?
  What can I do?
  thank you guys</p>
  <pre><code>export const Shopping = () =&gt; {
    const [user, setUser] = useState(null);
  
    useEffect(() =&gt; {
      const token = localStorage.getItem(&quot;token&quot;);
      if (!token) {
        setUser(null);
        return;
      }
  
    
      const response = {
        data: {
          user: {
            name: &quot;mohammad&quot;,
            email: &quot;mohamad@gmail.com&quot;,
          },
        },
      };
      if (!response.data.user) {
        setUser(null);
        return;
      } else {
        setUser({ user: response.data.user }); console.log(user.user.name);
      }
    }, []);
  
  
    return (
      &lt;div className=&quot;Shopping-Container&quot;&gt;
        &lt;NavbarStore user={user} /&gt;
        &lt;Routes&gt;
          &lt;Route path=&quot;/&quot; element={&lt;Store /&gt;} /&gt;
       &lt;/Routes&gt;
        &lt;Footer /&gt;
      &lt;/div&gt;
  </code></pre>