Skip to content

Commit

Permalink
fix: Reading localStorage for SSR mode (#3677)
Browse files Browse the repository at this point in the history
  • Loading branch information
GoodDayForSurf authored Aug 27, 2024
1 parent 691b1fe commit b139dbb
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/dx-site/src/components/banner.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import styles from './banner.module.scss';

const SHOW_BANNER_KEY = 'dx-show-banner';

let storage = { getItem: () => undefined, setItem: () => undefined };
try {
// eslint-disable-next-line no-undef
storage = window.localStorage;
} catch (e) {} // eslint-disable-line no-empty

const Banner = () => {
const [show, setShow] = React.useState(() => {
// eslint-disable-next-line no-undef
const showBanner = localStorage.getItem(SHOW_BANNER_KEY);
const showBanner = storage.getItem(SHOW_BANNER_KEY);
return showBanner !== '0';
});

Expand Down

0 comments on commit b139dbb

Please sign in to comment.