Skip to content

Commit

Permalink
During SSR, replace useLayoutEffect with useEffect
Browse files Browse the repository at this point in the history
CopyToClipboard behavior relies on this to get element.innerText,
so this was the easiest implementation to stop warnings *for valid code*
  • Loading branch information
ericclemmons committed Nov 18, 2021
1 parent 26f0efd commit a3f46b9
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions docs/src/pages/_app.page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react';
import * as React from 'react';
import Head from 'next/head';
import { useRouter } from 'next/router';
import { AmplifyProvider, ColorMode } from '@aws-amplify/ui-react';
Expand All @@ -8,11 +8,16 @@ import { Header } from '@/components/Layout/Header';
import { theme } from '../theme';
import '../styles/index.scss';

// suppress useLayoutEffect warnings when running outside a browser
// See: https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85#gistcomment-3886909
// @ts-ignore Cannot assign to 'useLayoutEffect' because it is a read-only property.ts(2540)
if (typeof window === 'undefined') React.useLayoutEffect = React.useEffect;

function MyApp({ Component, pageProps }) {
const router = useRouter();
const { platform = 'react' } = router.query;
const [colorMode, setColorMode] = useState<ColorMode>('system');
const [themeOverride, setThemeOverride] = useState('');
const [colorMode, setColorMode] = React.useState<ColorMode>('system');
const [themeOverride, setThemeOverride] = React.useState('');

const favicon =
process.env.NODE_ENV === 'development'
Expand Down

0 comments on commit a3f46b9

Please sign in to comment.