{"id":32901,"date":"2024-11-01T09:12:21","date_gmt":"2024-11-01T09:12:21","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=32901"},"modified":"2024-11-01T11:21:32","modified_gmt":"2024-11-01T11:21:32","slug":"react-course-using-web-storage","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/32901\/","title":{"rendered":"React Course: Using Web Storage"},"content":{"rendered":"<p>\n    When developing a web application, it is very important to store and manage user data on the client side.<br \/>\n    In this course, we will learn how to utilize web storage in a React application.<br \/>\n    Web storage is implemented through two main methods, namely session storage and local storage.\n<\/p>\n<h2>What is Web Storage?<\/h2>\n<p>\n    Web storage provides a way to store data on the client side.<br \/>\n    It is a simple API provided by the browser, allowing data to be stored and read without requesting the server.<br \/>\n    There are two main types of web storage.\n<\/p>\n<ul>\n<li><strong>Local Storage:<\/strong> Data is persistently stored even when the user is using the web application. The data remains even if the browser session ends.<\/li>\n<li><strong>Session Storage:<\/strong> Data is only maintained during the session of the browser tab or window. Closing the tab or exiting the browser will make the data disappear.<\/li>\n<\/ul>\n<h2>Using Web Storage in React<\/h2>\n<p>\n    Using web storage in React is very easy. Here, we will illustrate how to use local storage and session storage with a simple example.\n<\/p>\n<h3>1. Using Local Storage<\/h3>\n<p>\n    Let\u2019s create a simple component that saves and retrieves data using local storage.\n<\/p>\n<pre><code>\nimport React, { useState, useEffect } from 'react';\n\nconst LocalStorageExample = () =&gt; {\n    const [name, setName] = useState('');\n\n    useEffect(() =&gt; {\n        const storedName = localStorage.getItem('name');\n        if (storedName) {\n            setName(storedName);\n        }\n    }, []);\n\n    const handleChange = (event) =&gt; {\n        const newName = event.target.value;\n        setName(newName);\n        localStorage.setItem('name', newName);\n    };\n\n    return (\n        <div>\n            <h1>Local Storage Example<\/h1>\n            <input onchange=\"{handleChange}\" placeholder=\"Enter your name\" type=\"text\" value=\"{name}\"\/>\n            <p>Stored Name: {name}<\/p>\n        <\/div>\n    );\n};\n\nexport default LocalStorageExample;\n<\/code><\/pre>\n<p>\n    In the code above, we receive the user&#8217;s name, store it in local storage, and retrieve the saved name when the page is reloaded.<br \/>\n    We use the useEffect hook to read data from local storage when the component mounts.\n<\/p>\n<h3>2. Using Session Storage<\/h3>\n<p>\n    Next, let\u2019s create an example for saving and retrieving data using session storage.\n<\/p>\n<pre><code>\nimport React, { useState, useEffect } from 'react';\n\nconst SessionStorageExample = () =&gt; {\n    const [sessionData, setSessionData] = useState('');\n\n    useEffect(() =&gt; {\n        const storedData = sessionStorage.getItem('sessionData');\n        if (storedData) {\n            setSessionData(storedData);\n        }\n    }, []);\n\n    const handleChange = (event) =&gt; {\n        const newData = event.target.value;\n        setSessionData(newData);\n        sessionStorage.setItem('sessionData', newData);\n    };\n\n    return (\n        <div>\n            <h1>Session Storage Example<\/h1>\n            <input onchange=\"{handleChange}\" placeholder=\"Enter data to save in session\" type=\"text\" value=\"{sessionData}\"\/>\n            <p>Stored Data: {sessionData}<\/p>\n        <\/div>\n    );\n};\n\nexport default SessionStorageExample;\n<\/code><\/pre>\n<p>\n    In this example using session storage, the user&#8217;s input data can be maintained during the browser session.<br \/>\n    The data is automatically deleted when the session ends. Such functionality is useful in cases like shopping cart and temporary storage.\n<\/p>\n<h2>Web Storage API<\/h2>\n<p>\n    When dealing with web storage, the following API is used:\n<\/p>\n<ul>\n<li><strong>setItem(key, value):<\/strong> Stores a value for a specified key.<\/li>\n<li><strong>getItem(key):<\/strong> Returns the value for a specified key. Returns null if the key does not exist.<\/li>\n<li><strong>removeItem(key):<\/strong> Deletes the value stored for a specified key.<\/li>\n<li><strong>clear():<\/strong> Deletes all stored data.<\/li>\n<li><strong>key(index):<\/strong> Returns the key at the specified index.<\/li>\n<li><strong>length:<\/strong> Returns the number of stored items.<\/li>\n<\/ul>\n<h2>Advantages and Disadvantages of Web Storage<\/h2>\n<p>\n    Let\u2019s look at the advantages and disadvantages of using web storage.\n<\/p>\n<h3>Advantages<\/h3>\n<ul>\n<li><strong>Easy to Use:<\/strong> Web storage is very easy to use. You can store and read data without complex setup.<\/li>\n<li><strong>No Asynchronous Handling Needed:<\/strong> Data can be stored and retrieved immediately without server requests.<\/li>\n<li><strong>Throughput:<\/strong> Data reading and writing performance is excellent.<\/li>\n<\/ul>\n<h3>Disadvantages<\/h3>\n<ul>\n<li><strong>Storage Capacity Limit:<\/strong> Local storage is limited to about 5MB per domain.<\/li>\n<li><strong>Security Issues:<\/strong> Caution is needed when storing sensitive information. Data stored on the client side can be easily accessed, so privacy should be protected.<\/li>\n<li><strong>Browser Dependency:<\/strong> The behavior of web storage may vary depending on the browser used by the user.<\/li>\n<\/ul>\n<h2>Use Cases of Web Storage<\/h2>\n<p>\n    Web storage can be useful in various situations. Here are some common use cases.\n<\/p>\n<ul>\n<li><strong>User Preference Settings:<\/strong> You can store user-selected themes or language settings to provide the same environment during the next login.<\/li>\n<li><strong>Shopping Cart Feature:<\/strong> In online shopping malls, items added to the cart can be stored in local storage to retain data until the user checks out.<\/li>\n<li><strong>Temporary Storage:<\/strong> You can save data to local storage from user input forms to avoid losing data even if the user leaves the page.<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>\n    Web storage is a useful tool for storing and managing data on the client side in React applications.<br \/>\n    Through this course, you have learned the basic usage of local storage and session storage and explored various use cases.<br \/>\n    Try to utilize web storage in your future projects!\n<\/p>\n<h2>References<\/h2>\n<ul>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Web_Storage_API\">MDN Web Docs &#8211; Web Storage API<\/a><\/li>\n<li><a href=\"https:\/\/reactjs.org\/docs\/hooks-overview.html\">React Docs &#8211; Hooks Overview<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>When developing a web application, it is very important to store and manage user data on the client side. In this course, we will learn how to utilize web storage in a React application. Web storage is implemented through two main methods, namely session storage and local storage. What is Web Storage? Web storage provides &hellip; <a href=\"https:\/\/atmokpo.com\/w\/32901\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;React Course: Using Web Storage&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[123],"tags":[],"class_list":["post-32901","post","type-post","status-publish","format-standard","hentry","category-react-basics-course"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>React Course: Using Web Storage - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/32901\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"React Course: Using Web Storage - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"When developing a web application, it is very important to store and manage user data on the client side. In this course, we will learn how to utilize web storage in a React application. Web storage is implemented through two main methods, namely session storage and local storage. What is Web Storage? Web storage provides &hellip; \ub354 \ubcf4\uae30 &quot;React Course: Using Web Storage&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/32901\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:12:21+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:21:32+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"4\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/32901\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32901\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"React Course: Using Web Storage\",\"datePublished\":\"2024-11-01T09:12:21+00:00\",\"dateModified\":\"2024-11-01T11:21:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32901\/\"},\"wordCount\":625,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"React basics course\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/32901\/\",\"url\":\"https:\/\/atmokpo.com\/w\/32901\/\",\"name\":\"React Course: Using Web Storage - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:12:21+00:00\",\"dateModified\":\"2024-11-01T11:21:32+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32901\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/32901\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/32901\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"React Course: Using Web Storage\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"React Course: Using Web Storage - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/32901\/","og_locale":"ko_KR","og_type":"article","og_title":"React Course: Using Web Storage - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"When developing a web application, it is very important to store and manage user data on the client side. In this course, we will learn how to utilize web storage in a React application. Web storage is implemented through two main methods, namely session storage and local storage. What is Web Storage? Web storage provides &hellip; \ub354 \ubcf4\uae30 \"React Course: Using Web Storage\"","og_url":"https:\/\/atmokpo.com\/w\/32901\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:12:21+00:00","article_modified_time":"2024-11-01T11:21:32+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"4\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/32901\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/32901\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"React Course: Using Web Storage","datePublished":"2024-11-01T09:12:21+00:00","dateModified":"2024-11-01T11:21:32+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/32901\/"},"wordCount":625,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["React basics course"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/32901\/","url":"https:\/\/atmokpo.com\/w\/32901\/","name":"React Course: Using Web Storage - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:12:21+00:00","dateModified":"2024-11-01T11:21:32+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/32901\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/32901\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/32901\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"React Course: Using Web Storage"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32901","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=32901"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32901\/revisions"}],"predecessor-version":[{"id":32902,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32901\/revisions\/32902"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=32901"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=32901"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=32901"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}