<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Shahrukh Azeem on Medium]]></title>
        <description><![CDATA[Stories by Shahrukh Azeem on Medium]]></description>
        <link>https://medium.com/@shahrukhAzeem?source=rss-715afba29b4e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*rpQDfx4Hu_Pjx-GI.</url>
            <title>Stories by Shahrukh Azeem on Medium</title>
            <link>https://medium.com/@shahrukhAzeem?source=rss-715afba29b4e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 21:53:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shahrukhAzeem/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Handling window in Gatsby]]></title>
            <link>https://medium.com/@shahrukhAzeem/handling-window-in-gatsby-cd21c4877d48?source=rss-715afba29b4e------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd21c4877d48</guid>
            <category><![CDATA[gatsby]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[error-handling]]></category>
            <category><![CDATA[localstorage]]></category>
            <dc:creator><![CDATA[Shahrukh Azeem]]></dc:creator>
            <pubDate>Mon, 10 Aug 2020 07:06:48 GMT</pubDate>
            <atom:updated>2020-08-10T07:11:20.477Z</atom:updated>
            <content:encoded><![CDATA[<h3>Handling window attributes in Gatsby</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*2Z567kw6gyx_KHYs0GVzdw.jpeg" /></figure><p>Gatsby is a powerful framework based on react.js for static websites but it can be used for small to medium-sized web applications. In most web applications, we require user authentication via web token. The simplest way to store a web token is to store it in the localStorage of window that is accessible in the whole application. The general way of setting a token in localStorage after getting it from server is shown below</p><blockquote>window.localStorage.setItem(“token, webtoken)</blockquote><p>In Gatsby, you can access the window attributes in development mode but when you build the application it will through error that window is not defined and you cannot access window like this because window object is accessible only after the component is mounted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*8Wu2L0dXFjeJoY4RxI-OcQ.png" /><figcaption>Error shown after gatsby build while using window.locationStorage</figcaption></figure><p>Therefore you will need to use either componentDidMount method for Class Component or useEffect hook for functional component.</p><p>For Class component</p><blockquote>componentDidMount() {<br> window.localStorage.setItem(“token, webtoken)<br>}</blockquote><p>For Functional component</p><blockquote>const [tokenLocalStorage, setLocalStorageKey] = useState(undefined)</blockquote><blockquote>useEffect(() =&gt; {</blockquote><blockquote>setLocalStorageKey(window.localStorage.getItem(“token”))</blockquote><blockquote>}, [tokenLocalStorage])</blockquote><p>Likewise, sessionStorage and other window object properties can be used through the above cited method.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd21c4877d48" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>