1.0.5 • Published 6 years ago

gatsby-window v1.0.5

Weekly downloads
16
License
ISC
Repository
github
Last release
6 years ago

Example

$ npm install gatsby-window --save

or

$ yarn add gatsby-window

Import usage

import { windowGatsby } from "gatsby-window" 
// ES2015 modules
const { windowGatsby } = require("gatsby-window");

Use example

import React, { Component } from "react";
import { windowGatsby as windowG } from "gatsby-window"

export default class GatsbyPage extends Component {

    componentDidMount() {
        // Using gatsby-window in only-browser methods
        const { sessionStorage } = windowG
        sessionStorage.setItem("componentDidMount", "Using session storage in Gatsby after build!");
        console.log(sessionStorage.getItem("componentDidMount"));
    };

    componentWillUnmount() {
        // Using gatsby-window in only-browser methods
        windowG.sessionStorage.setItem("componentWillUnmount", "Using session storage in Gatsby after build!");
        console.log(windowG.sessionStorage.getItem("componentWillUnmount"));
    };

    render() {
        // Using gatsby-window in other methods
        if (windowG) {
            const { sessionStorage } = windowG
            sessionStorage.setItem("key", "Using session storage in Gatsby after build!");
            console.log(sessionStorage.getItem("key"));
        }

        return (
            <h1>A</h1>
        )
    }
}