<?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 Alina Pisarenko on Medium]]></title>
        <description><![CDATA[Stories by Alina Pisarenko on Medium]]></description>
        <link>https://medium.com/@pisarenko.alina?source=rss-34179174c2a6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Y5MKAowNzDVZuy2jm-qutQ@2x.jpeg</url>
            <title>Stories by Alina Pisarenko on Medium</title>
            <link>https://medium.com/@pisarenko.alina?source=rss-34179174c2a6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 11:24:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pisarenko.alina/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[React Login Persistence using localStorage and useEffect]]></title>
            <link>https://medium.com/@pisarenko.alina/react-login-persistence-using-localstorage-and-useeffect-6b6d34039fc9?source=rss-34179174c2a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b6d34039fc9</guid>
            <category><![CDATA[persistence]]></category>
            <category><![CDATA[react-hook-useeffect]]></category>
            <category><![CDATA[login]]></category>
            <category><![CDATA[localstorage]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Alina Pisarenko]]></dc:creator>
            <pubDate>Wed, 08 Jun 2022 04:31:40 GMT</pubDate>
            <atom:updated>2022-06-08T13:56:52.455Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*irusb25Ra56XVLZzOHCKZg.png" /></figure><p>It can be quite challenging to figure out how to persist logged-in user in react for the first time. This post is a simple guide to solving that problem.</p><p>Let’s divide the whole process into a few small steps:</p><ol><li>Creating login form</li><li>Handling log in event</li><li>Using useEffect hook to check if a user is currently logged in</li><li>Logging out and resetting all data</li></ol><h3>Creating login form</h3><p>The first thing to do is to create a new React application and a component, where you want your login form to be. I’m just going to create a login form in App.js.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qevDsWkUl37njSfcCaBz-w.png" /></figure><p>I’m using useState hook here for the form itself, as well as creating a user state and then defining a conditional that will either display a login form(if we don’t have a user) or a &lt;div&gt; that includes a welcome message and a logout button.</p><h3>Handling log in event</h3><p>After our form is ready it’s time to write the function that will handle a submit event.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G_EYilKAkGcQYLrcPlaxzg.png" /></figure><p>This function creates a user variable and assigns it a username and password values. Then it sends that info to a server(I’m using db.json as my database for all the user&#39;s information) and once the response is back, it changes user state and saves user info to local storage.</p><p><strong>But what is the local storage and where we can find it?</strong></p><p><strong>localStorage</strong> is a property that allows JavaScript sites and apps to save key-value pairs in a web browser with no expiration date. This means the data stored in the browser will persist even after the browser window is closed. <strong>To view local storage</strong> simply go to the developer tools, then go to the Application tab. In the Storage section expand Local Storage. After that, you’ll see all your browser’s local storage there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x4jWi4JjlDVY1IVE6aPRLQ.png" /></figure><p>Now, when we run the code and submit the form, we should get that welcome message and our user information should be saved in local storage. There is one more step left to make the login persistent.</p><h3>Using useEffect hook to check if a user is currently logged in</h3><p>Once we load the page we need to check if the user is logged in already. For that, we will use useEffect hook.</p><p>First, we need to import useEffect from React.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*-ATZ-yr585gjf9nyjY4mbA.png" /></figure><p>Now we can apply useEffect to our code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wg4DTB-ywkNXrlYAwDk-SA.png" /></figure><p>Here we are getting a user item from the local storage and if it exists, assigning it to the user state. Also, using an empty dependency array so it only runs the first time the app loads.</p><p>Now our login is persistent. The last step is to create a function that will handle logout.</p><h3>Logging out and resetting all data</h3><p>This step is really simple, all we need to do is reset all data and clean up the local storage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*sFmJD-LJLOrdqbzYo0pF3Q.png" /></figure><p>Now our app should be working perfectly.</p><p>Congrats! We are done!</p><h3>Conclusion</h3><p>In this post, I created a persistent login in react using localStorage and useEffect. Breaking down the whole process step by step really helped me to understand the concept. I hope, this post will save you some trouble, especially if you are just like me at the beginning of your coding journey!</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b6d34039fc9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What does fetch() do?]]></title>
            <link>https://medium.com/@pisarenko.alina/what-does-fetch-do-5284a2ddb6f4?source=rss-34179174c2a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/5284a2ddb6f4</guid>
            <category><![CDATA[data-fetching]]></category>
            <category><![CDATA[fetch-api]]></category>
            <category><![CDATA[post-request]]></category>
            <category><![CDATA[fetch]]></category>
            <category><![CDATA[get-request]]></category>
            <dc:creator><![CDATA[Alina Pisarenko]]></dc:creator>
            <pubDate>Fri, 13 May 2022 04:51:30 GMT</pubDate>
            <atom:updated>2022-05-13T04:51:30.903Z</atom:updated>
            <content:encoded><![CDATA[<p>I just recently started my coding journey, so I totally understand that frustration, when you are trying to learn something from the scratch. In this post(my first one ever), I’ll try to talk about a few fetch requests in a really simple beginner-friendly way.</p><p>Let’s start with defining what <strong>Fetch API </strong>is. It’s a simple interface for fetching resources, which makes it easy for us to make web requests and handle responses. And who doesn’t like simple? Fetch API also provides a global <a href="https://developer.mozilla.org/en-US/docs/Web/API/fetch"><strong>fetch()</strong></a> method that gives us an easy, logical way to request to the server and load the information on the web pages. Another great thing about it is that by using Fetch API, you don’t have to install an external library, so it reduces the built file size.</p><p>In this post, I’ll provide information about a few fetch() requests:</p><ul><li>GET</li><li>POST</li><li>DELETE</li></ul><p>Let’s start with <strong>GET</strong>.</p><p>This basic fetch request is really easy to set up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*iY32xjDdQTXK2YpZLjyFug.png" /></figure><p>So, what exactly are we doing here?</p><p>We are getting some data from our local database. fetch() GET request takes in one argument, the path to the data we are trying to get. But instead of returning JSON response, it returns a <strong>PROMISE</strong>, that resolves with a response object. However, we didn’t receive JSON object just yet. We have an object that is a representation of the entire HTTP response. To convert it into JSON, we need to use the<strong> json()</strong> method. Now we have the data, but it still needs to be processed, so we are adding another .then() statement, that includes a callback function with an argument (data). Finally, inside this function, we are ready to console.log our data.</p><p>Now, when we know how the basic fetch request work, we can learn how to post new data in our database.</p><p>Here comes <strong>POST</strong> request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*VU4_qAVkFIVU1gbMU94rvw.png" /></figure><p>This time fetch() takes in two arguments: the path to the data and an object. This object includes all the necessary iformation about that new piece of data we are sending. First goes the <strong>method: “POST”</strong>. Pretty straightforward: we are posting new data. Next, headers. Here we are explaining what type of content we are sending(<strong>“application/json”</strong>). And last, but not least, we are adding a body(content), while also converting our object into JSON string. And after that, we are just going through the same steps as in GET request and getting our new data from the database. There is one new line in that code though. <strong>.catch((error))</strong> does exactly what it says. If there is an error it will catch it and console.log it for us. What a great way to always stay on top of your code!</p><p>One more request I wanted to look into is <strong>DELETE</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*g7XcKtaxQvSRMaAQEj2kQg.png" /></figure><p>So what’s happening here?</p><p>Let’s say we have a piece of data that we want to remove from our database. Our fetch request will take two arguments, just like in the POST method: the path and the object, that describes our request. There is one little difference in our path though. This time we need to specify which piece of data we want to remove. So we are using an id of the object in the path: <strong>/id. </strong>After we described a method (“DELETE”), our request is sent and we are getting a response back. We already know that we can’t just use this response, we need to parse it first. But once we are done with that, we can go ahead and use that data in any desired way.</p><p>In this post, I’ve covered how to make basic GET, POST, and DELETE requests in JavaScript with the Fetch API. If you are interested in learning more, I highly recommend looking into PATCH request as your next step. Here is some information, that I found really helpful:</p><p><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH">PATCH - HTTP | MDN</a></p><p>You can never go wrong with MDN!</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5284a2ddb6f4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>