title: Array.length is returning undefined when page is refreshed
body: <p>I have an array that returns undefined when I check the length (array.length) only the page is refreshed. </p>
  
  <p>If I open my local environment in a new tab in chrome, everything works fine, and I get the length of the array. Only after refreshing the page once, the page crashes and I get the following error: 
  "TypeError: Cannot read property 'length' of undefined".</p>
  
  <p>I am using React, React's Context API (I am getting the array from the context provider) and Nextjs for the project. I have a feeling this issue connected with SSR, but I'm not entirely sure. </p>
  
  <p>Here is the relevant code connected with the problem. </p>
  
  <p><strong>Context Provider</strong></p>
  
  <pre><code>export function CartProvider(props) {
      let initializeState;
      if (typeof window !== 'undefined') {
          initializeState = JSON.parse(sessionStorage.getItem('cart'));
          if (initializeState === null) {
              initializeState = [];
          }
      }
  
      // Sets the cart
      const [ cart, setCart ] = useState(initializeState);
      return (
          &lt;CartContext.Provider
              value={{ cart, setCart, checkCart, addItem, deleteItem, quantityIncrease, quantityDecrease }}
          &gt;
              {props.children}
          &lt;/CartContext.Provider&gt;
      );
  }
  </code></pre>
  
  <p>And this is the code that is consuming the Context Provider</p>
  
  <p><strong>Cart.js</strong></p>
  
  <pre><code>import React, { Fragment, useContext } from 'react';
  import ShoppingCart from '../components/ShoppingCart';
  import { CartContext } from '../contexts/CartContext';
  const cart = () =&gt; {
      const { cart } = useContext(CartContext);
  
      return (
          &lt;Fragment&gt;
              {cart.length !== 0 ? (
                  &lt;ShoppingCart /&gt;
              ) : (
                  &lt;div&gt;
                      &lt;h1&gt;Your cart is empty&lt;/h1&gt;
                  &lt;/div&gt;
              )}
          &lt;/Fragment&gt;
      );
  };
  
  export default cart;
  </code></pre>
  
  <p>Any help is greatly appreciated!</p>