title: Getting warning: Invalid hook call and Type error: cannot read properties of null (reading 'useContext') using Material UI component
body: <p>This is the component:</p>
  <pre><code>import React, { useEffect } from &quot;react&quot;;
  import { useStore } from &quot;../zustand/store&quot;;
  import shallow from &quot;zustand/shallow&quot;;
  import Grid from &quot;@mui/material/Grid&quot;;
  
  export const JoinChat = () =&gt; {
      const [userCount, setUserCount] = useStore(
          (state) =&gt; [state.userCount, state.setUserCount],
          shallow
      );
      const setChat = useStore((state) =&gt; state.setChat);
      const socket = useStore((state) =&gt; state.socket);
  
      useEffect(() =&gt; {
          socket.on(&quot;user_count&quot;, (data) =&gt; {
              console.log(&quot;user count run in join chat&quot;);
              setUserCount(data);
          });
      }, [socket, setUserCount]);
  
      const joinChat = async () =&gt; {
          if (&quot;geolocation&quot; in navigator) {
              await navigator.geolocation.getCurrentPosition(async (pos) =&gt; {
                  const location = {
                      x: pos.coords.longitude,
                      y: pos.coords.latitude,
                  };
                  await socket.emit(&quot;create_chat&quot;, location);
                  setChat(true);
              });
          } else {
              alert(&quot;You location is not available&quot;);
          }
      };
  
      return (
          &lt;Grid&gt;
              &lt;div&gt;
                  {userCount ? &lt;p&gt;People online {userCount}&lt;/p&gt; : null}
                  &lt;button onClick={joinChat}&gt;Join chat&lt;/button&gt;
              &lt;/div&gt;
          &lt;/Grid&gt;
      );
  };
  
  </code></pre>
  <p>I get the following error in the console when I  use grid to wrap the div:
  <a href="https://i.stack.imgur.com/Zee3d.png" rel="nofollow noreferrer">here</a></p>
  <p>It renders fine without warning or error if I get rid of the material UI component</p>