Maintaining/accessing global state in Gatsby site
up vote
0
down vote
favorite
I am currently trying to implement a fairly simple feature in a Gatsby JS driven site, which was built by someone else and am facing the following problem:
The page currently darkens the background when a modal is opened, I would like to have the background blur instead though. In order to achieve the darker background, the component for the modal includes a div, with fixed position, which fills the window, the css of which is as follows:
.background_fader {
display: block;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.2);
cursor: pointer;
}
I have tried using filter: blur(20px)
instead of the background-color
, but to no avail. It appears, that even when I change the z-index
of the div, I am not able to blur the background, but would rather have to add the filter
property at the wrapper of the page, i.e. much higher up in the hierarchy.
I have some experience with react and almost none with Gatsby, so please excuse if this question is simple/ rooted in a fundamental misconception.
What I have dealt with so far, were pages which used Redux as a centralized state and the much wider question which arose in implementing the blurring is this:
How do I add a state to the root-component of the Gatsby page in order to pass relevant aspects down to child components and thereby rerender the page?
After doing some research, I came to the conclusion, that it should be possible to use the wrapRootElement
function from gatsby-browser.js in order to define a state at the root of the app, but I am having trouble implementing this, because the only props I seem to be able to access in the "root" component, which is generated from layouts/index.js are the data retrieved from Graphql.
Currently the layouts/index.js looks like this:
import React from 'react';
import graphql from 'graphql';
import Helmet from 'react-helmet';
import classNames from 'classnames';
// import 'bootstrap/dist/css/bootstrap.min.css';
import './reset.css';
import '../components/styleguide/index.less';
import Feedback from '../components/feedback';
import Navbar from '../components/Nav';
import Footer from '../components/footer';
import Subscribe from '../components/Subscribe';
import './index.less';
export default ({
children, location, data: {
FooterSettings: { edges: [{ node: { frontmatter: footerData } }] },
NavbarSettings: { edges: [{ node: { frontmatter: navbarSettings } }] },
HomepageSettings: { edges: [{ node: { frontmatter: homepageSettings } }] }
}
}) => {
const wrapperClasses = classNames(
'page-wrapper',
{
'page-wrapper--custom': location.pathname.split('/')[1]
},
`page-wrapper--${location.pathname.split('/')[1]}`
);
return (
<div className={wrapperClasses}>
<Helmet>
<html lang="uk" />
</Helmet>
<Navbar location={location.pathname} className={location.pathname.split('/')[1]} {...navbarSettings} />
<Feedback
location={location}
email={homepageSettings.contactFormEmail}
title={homepageSettings.contactFormTitle}
/>
{children()}
<Subscribe email={homepageSettings.contactFormEmail} className={location.pathname.split('/')[1]} />
<Footer {...footerData} {...navbarSettings} className={location.pathname.split('/')[1]} />
</div>
);
};
export const pageQuery = // very long query which appears to be sound
So, returning to my question:
How do can I dynamically add or remove a class-name to wrapperClasses
based on a state that I pass to the <Feedback
component and where would I instantiate this state to reoad the entire page, when it changes.
Thanks in advance folks.
reactjs jsx gatsby
add a comment |
up vote
0
down vote
favorite
I am currently trying to implement a fairly simple feature in a Gatsby JS driven site, which was built by someone else and am facing the following problem:
The page currently darkens the background when a modal is opened, I would like to have the background blur instead though. In order to achieve the darker background, the component for the modal includes a div, with fixed position, which fills the window, the css of which is as follows:
.background_fader {
display: block;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.2);
cursor: pointer;
}
I have tried using filter: blur(20px)
instead of the background-color
, but to no avail. It appears, that even when I change the z-index
of the div, I am not able to blur the background, but would rather have to add the filter
property at the wrapper of the page, i.e. much higher up in the hierarchy.
I have some experience with react and almost none with Gatsby, so please excuse if this question is simple/ rooted in a fundamental misconception.
What I have dealt with so far, were pages which used Redux as a centralized state and the much wider question which arose in implementing the blurring is this:
How do I add a state to the root-component of the Gatsby page in order to pass relevant aspects down to child components and thereby rerender the page?
After doing some research, I came to the conclusion, that it should be possible to use the wrapRootElement
function from gatsby-browser.js in order to define a state at the root of the app, but I am having trouble implementing this, because the only props I seem to be able to access in the "root" component, which is generated from layouts/index.js are the data retrieved from Graphql.
Currently the layouts/index.js looks like this:
import React from 'react';
import graphql from 'graphql';
import Helmet from 'react-helmet';
import classNames from 'classnames';
// import 'bootstrap/dist/css/bootstrap.min.css';
import './reset.css';
import '../components/styleguide/index.less';
import Feedback from '../components/feedback';
import Navbar from '../components/Nav';
import Footer from '../components/footer';
import Subscribe from '../components/Subscribe';
import './index.less';
export default ({
children, location, data: {
FooterSettings: { edges: [{ node: { frontmatter: footerData } }] },
NavbarSettings: { edges: [{ node: { frontmatter: navbarSettings } }] },
HomepageSettings: { edges: [{ node: { frontmatter: homepageSettings } }] }
}
}) => {
const wrapperClasses = classNames(
'page-wrapper',
{
'page-wrapper--custom': location.pathname.split('/')[1]
},
`page-wrapper--${location.pathname.split('/')[1]}`
);
return (
<div className={wrapperClasses}>
<Helmet>
<html lang="uk" />
</Helmet>
<Navbar location={location.pathname} className={location.pathname.split('/')[1]} {...navbarSettings} />
<Feedback
location={location}
email={homepageSettings.contactFormEmail}
title={homepageSettings.contactFormTitle}
/>
{children()}
<Subscribe email={homepageSettings.contactFormEmail} className={location.pathname.split('/')[1]} />
<Footer {...footerData} {...navbarSettings} className={location.pathname.split('/')[1]} />
</div>
);
};
export const pageQuery = // very long query which appears to be sound
So, returning to my question:
How do can I dynamically add or remove a class-name to wrapperClasses
based on a state that I pass to the <Feedback
component and where would I instantiate this state to reoad the entire page, when it changes.
Thanks in advance folks.
reactjs jsx gatsby
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am currently trying to implement a fairly simple feature in a Gatsby JS driven site, which was built by someone else and am facing the following problem:
The page currently darkens the background when a modal is opened, I would like to have the background blur instead though. In order to achieve the darker background, the component for the modal includes a div, with fixed position, which fills the window, the css of which is as follows:
.background_fader {
display: block;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.2);
cursor: pointer;
}
I have tried using filter: blur(20px)
instead of the background-color
, but to no avail. It appears, that even when I change the z-index
of the div, I am not able to blur the background, but would rather have to add the filter
property at the wrapper of the page, i.e. much higher up in the hierarchy.
I have some experience with react and almost none with Gatsby, so please excuse if this question is simple/ rooted in a fundamental misconception.
What I have dealt with so far, were pages which used Redux as a centralized state and the much wider question which arose in implementing the blurring is this:
How do I add a state to the root-component of the Gatsby page in order to pass relevant aspects down to child components and thereby rerender the page?
After doing some research, I came to the conclusion, that it should be possible to use the wrapRootElement
function from gatsby-browser.js in order to define a state at the root of the app, but I am having trouble implementing this, because the only props I seem to be able to access in the "root" component, which is generated from layouts/index.js are the data retrieved from Graphql.
Currently the layouts/index.js looks like this:
import React from 'react';
import graphql from 'graphql';
import Helmet from 'react-helmet';
import classNames from 'classnames';
// import 'bootstrap/dist/css/bootstrap.min.css';
import './reset.css';
import '../components/styleguide/index.less';
import Feedback from '../components/feedback';
import Navbar from '../components/Nav';
import Footer from '../components/footer';
import Subscribe from '../components/Subscribe';
import './index.less';
export default ({
children, location, data: {
FooterSettings: { edges: [{ node: { frontmatter: footerData } }] },
NavbarSettings: { edges: [{ node: { frontmatter: navbarSettings } }] },
HomepageSettings: { edges: [{ node: { frontmatter: homepageSettings } }] }
}
}) => {
const wrapperClasses = classNames(
'page-wrapper',
{
'page-wrapper--custom': location.pathname.split('/')[1]
},
`page-wrapper--${location.pathname.split('/')[1]}`
);
return (
<div className={wrapperClasses}>
<Helmet>
<html lang="uk" />
</Helmet>
<Navbar location={location.pathname} className={location.pathname.split('/')[1]} {...navbarSettings} />
<Feedback
location={location}
email={homepageSettings.contactFormEmail}
title={homepageSettings.contactFormTitle}
/>
{children()}
<Subscribe email={homepageSettings.contactFormEmail} className={location.pathname.split('/')[1]} />
<Footer {...footerData} {...navbarSettings} className={location.pathname.split('/')[1]} />
</div>
);
};
export const pageQuery = // very long query which appears to be sound
So, returning to my question:
How do can I dynamically add or remove a class-name to wrapperClasses
based on a state that I pass to the <Feedback
component and where would I instantiate this state to reoad the entire page, when it changes.
Thanks in advance folks.
reactjs jsx gatsby
I am currently trying to implement a fairly simple feature in a Gatsby JS driven site, which was built by someone else and am facing the following problem:
The page currently darkens the background when a modal is opened, I would like to have the background blur instead though. In order to achieve the darker background, the component for the modal includes a div, with fixed position, which fills the window, the css of which is as follows:
.background_fader {
display: block;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.2);
cursor: pointer;
}
I have tried using filter: blur(20px)
instead of the background-color
, but to no avail. It appears, that even when I change the z-index
of the div, I am not able to blur the background, but would rather have to add the filter
property at the wrapper of the page, i.e. much higher up in the hierarchy.
I have some experience with react and almost none with Gatsby, so please excuse if this question is simple/ rooted in a fundamental misconception.
What I have dealt with so far, were pages which used Redux as a centralized state and the much wider question which arose in implementing the blurring is this:
How do I add a state to the root-component of the Gatsby page in order to pass relevant aspects down to child components and thereby rerender the page?
After doing some research, I came to the conclusion, that it should be possible to use the wrapRootElement
function from gatsby-browser.js in order to define a state at the root of the app, but I am having trouble implementing this, because the only props I seem to be able to access in the "root" component, which is generated from layouts/index.js are the data retrieved from Graphql.
Currently the layouts/index.js looks like this:
import React from 'react';
import graphql from 'graphql';
import Helmet from 'react-helmet';
import classNames from 'classnames';
// import 'bootstrap/dist/css/bootstrap.min.css';
import './reset.css';
import '../components/styleguide/index.less';
import Feedback from '../components/feedback';
import Navbar from '../components/Nav';
import Footer from '../components/footer';
import Subscribe from '../components/Subscribe';
import './index.less';
export default ({
children, location, data: {
FooterSettings: { edges: [{ node: { frontmatter: footerData } }] },
NavbarSettings: { edges: [{ node: { frontmatter: navbarSettings } }] },
HomepageSettings: { edges: [{ node: { frontmatter: homepageSettings } }] }
}
}) => {
const wrapperClasses = classNames(
'page-wrapper',
{
'page-wrapper--custom': location.pathname.split('/')[1]
},
`page-wrapper--${location.pathname.split('/')[1]}`
);
return (
<div className={wrapperClasses}>
<Helmet>
<html lang="uk" />
</Helmet>
<Navbar location={location.pathname} className={location.pathname.split('/')[1]} {...navbarSettings} />
<Feedback
location={location}
email={homepageSettings.contactFormEmail}
title={homepageSettings.contactFormTitle}
/>
{children()}
<Subscribe email={homepageSettings.contactFormEmail} className={location.pathname.split('/')[1]} />
<Footer {...footerData} {...navbarSettings} className={location.pathname.split('/')[1]} />
</div>
);
};
export const pageQuery = // very long query which appears to be sound
So, returning to my question:
How do can I dynamically add or remove a class-name to wrapperClasses
based on a state that I pass to the <Feedback
component and where would I instantiate this state to reoad the entire page, when it changes.
Thanks in advance folks.
reactjs jsx gatsby
reactjs jsx gatsby
asked Nov 18 at 20:45
MTTI
18418
18418
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53365278%2fmaintaining-accessing-global-state-in-gatsby-site%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown