title: How to detect window size in Next.js SSR using react hook?
body: <p>I am building an app using Next.js and <a href="https://github.com/airbnb/react-dates" rel="noreferrer">react-dates</a>.</p>
  <p>I have two component <strong>DateRangePicker</strong> component and <strong>DayPickerRangeController</strong> component.</p>
  <p>I want to render <strong>DateRangePicker</strong> when the window's width is bigger than size 1180px, if the size is smaller than this I want to render <strong>DayPickerRangeController</strong> instead.</p>
  <p>Here is the code:</p>
  <pre><code>      windowSize &gt; 1180 ?
             &lt;DateRangePicker
               startDatePlaceholderText=&quot;Start&quot;
               startDate={startDate}
               startDateId=&quot;startDate&quot;
               onDatesChange={handleOnDateChange}
               endDate={endDate}
               endDateId=&quot;endDate&quot;
               focusedInput={focus}
               transitionDuration={0}
               onFocusChange={(focusedInput) =&gt; {
                 if (!focusedInput) {
                   setFocus(&quot;startDate&quot;)
                 } else {
                   setFocus(focusedInput)
                  }
                 }}
                  /&gt; :
               &lt;DayPickerRangeController
                 isOutsideRange={day =&gt; isInclusivelyBeforeDay(day, moment().add(-1, 'days'))}
                 startDate={startDate}
                 onDatesChange={handleOnDateChange}
                 endDate={endDate}
                 focusedInput={focus}
                 onFocusChange={(focusedInput) =&gt; {
                 if (!focusedInput) {
                   setFocus(&quot;startDate&quot;)
                   } else {
                    setFocus(focusedInput)
                   }
                 }}
                /&gt; 
            }
  </code></pre>
  <p>I normally use react hook with window object to detect window screen width like <a href="https://usehooks.com/useWindowSize/" rel="noreferrer">this</a></p>
  <p>But I found that this way is not available when ssr because ssr rendering does not have window object.</p>
  <p>Is there an alternative way I can get window size safely regardless of ssr?</p>