Skip to content

Commit

Permalink
fix: Add useEffect and state to conditionally render footer
Browse files Browse the repository at this point in the history
  • Loading branch information
LizBaker committed Sep 15, 2021
1 parent e7eb73c commit f6ac192
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
15 changes: 10 additions & 5 deletions src/@newrelic/gatsby-theme-newrelic/components/Logo.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 10 additions & 14 deletions src/layouts/QuickStartLayout.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect, useState } from 'react';
import {
Layout,
GlobalHeader,
Expand All @@ -8,19 +8,15 @@ import PropTypes from 'prop-types';
import { css } from '@emotion/react';
import '../components/styles.scss';

const getSidebarWidth = () => {
switch (true) {
case !window.location:
return 0;
case window.location.pathname === '/instant-observability/':
// this value matches '--sidebar-width' variable defined in instant-observability.js
return 300;
default:
return 0;
}
};

const QuickStartLayout = ({ children }) => {
const [sidebarWidth, setSidebarWidth] = useState(0);

useEffect(() => {
if (window.location.pathname === '/instant-observability/') {
setSidebarWidth(300);
} else setSidebarWidth(0);
}, [children]);

return (
<>
<GlobalHeader activeSite={NR_SITES.IO} />
Expand All @@ -43,7 +39,7 @@ const QuickStartLayout = ({ children }) => {
</Layout.Main>
<Layout.Footer
css={css`
--sidebar-offset: ${getSidebarWidth()}px;
--sidebar-offset: ${sidebarWidth}px;
max-width: calc(var(--site-max-width) - var(--sidebar-offset));
Expand Down

0 comments on commit f6ac192

Please sign in to comment.