{"id":32927,"date":"2024-11-01T09:12:32","date_gmt":"2024-11-01T09:12:32","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=32927"},"modified":"2024-11-01T11:21:26","modified_gmt":"2024-11-01T11:21:26","slug":"react-course-diary-app-example-and-optimization","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/32927\/","title":{"rendered":"React Course: Diary App Example and Optimization"},"content":{"rendered":"<p>In recent years, React has established itself as one of the most popular libraries for web application development. With React, you can create fast, efficient, and reusable UI components. In this tutorial, we will examine how to create a simple diary app using React. Additionally, we will discuss performance optimization.<\/p>\n<h2>1. Project Setup<\/h2>\n<p>Before getting started, you need to have Node.js and npm (Node Package Manager) installed. These tools are essential for creating and managing React projects. Once the installation is complete, you can create a new React project using the following command.<\/p>\n<pre><code>npx create-react-app diary-app<\/code><\/pre>\n<p>This command creates a basic React project template. After moving into the project folder, you can install the required libraries.<\/p>\n<pre><code>cd diary-app<\/code><\/pre>\n<p>Next, we will install the libraries needed for state management and styling in the diary app.<\/p>\n<pre><code>npm install axios bootstrap<\/code><\/pre>\n<h2>2. Designing the Basic Structure<\/h2>\n<p>Now, let&#8217;s design the basic project structure. The diary app is divided into the following main components:<\/p>\n<ul>\n<li><strong>DiaryList<\/strong>: A component that displays the list of diary entries.<\/li>\n<li><strong>DiaryEntry<\/strong>: A component for creating or editing a new diary entry.<\/li>\n<li><strong>Header<\/strong>: A header component that includes the app title and navigation links.<\/li>\n<\/ul>\n<p>These components will be created as individual files within the <code>src<\/code> folder.<\/p>\n<h2>3. Implementing the DiaryList Component<\/h2>\n<p>Create a <strong>DiaryList.js<\/strong> file and add the following code.<\/p>\n<pre><code>import React from 'react';\n\nconst DiaryList = ({ diaries }) => {\n    return (\n        <div className=\"diary-list\">\n            <h2>My Diary List<\/h2>\n            {diaries.length === 0 ? (\n                <p>No diaries available.<\/p>\n            ) : (\n                diaries.map(diary => (\n                    <div key=\"{diary.id}\">\n                        <h3>{diary.title}<\/h3>\n                        <p>{diary.content}<\/p>\n                        <hr\/>\n                    <\/div>\n                ))\n            )}\n        <\/div>\n    );\n};\n\nexport default DiaryList;<\/code><\/pre>\n<p>This component displays the title and content of each diary entry through the <code>diaries<\/code> array received as a prop. If there are no diaries, it outputs an appropriate message.<\/p>\n<h2>4. Implementing the DiaryEntry Component<\/h2>\n<p>Now, create a <strong>DiaryEntry.js<\/strong> file and implement a form that allows the user to write a diary entry.<\/p>\n<pre><code>import React, { useState } from 'react';\n\nconst DiaryEntry = ({ onSubmit }) => {\n    const [title, setTitle] = useState('');\n    const [content, setContent] = useState('');\n\n    const handleSubmit = (e) => {\n        e.preventDefault();\n        onSubmit({ title, content });\n        setTitle('');\n        setContent('');\n    };\n\n    return (\n        <form onSubmit=\"{handleSubmit}\">\n            <input onChange=\"{(e) => setTitle(e.target.value)}\" placeholder=\"Title\" type=\"text\" value=\"{title}\" required \/>\n            <textarea onChange=\"{(e) => setContent(e.target.value)}\" placeholder=\"Content\" value=\"{content}\" required \/>\n            <button type=\"submit\">Save<\/button>\n        <\/form>\n    );\n};\n\nexport default DiaryEntry;<\/code><\/pre>\n<p>This component uses the <code>useState<\/code> hook to manage the title and content, and it calls the function passed via the <code>onSubmit<\/code> prop when the user submits the form to save the diary entry.<\/p>\n<h2>5. Implementing the Header Component<\/h2>\n<p>Create a <strong>Header.js<\/strong> file and implement the app&#8217;s header.<\/p>\n<pre><code>import React from 'react';\n\nconst Header = () => {\n    return (\n        <header>\n            <h1>My Diary<\/h1>\n        <\/header>\n    );\n};\n\nexport default Header;<\/code><\/pre>\n<h2>6. Configuring the App Component<\/h2>\n<p>Now, we will modify the <strong>App.js<\/strong> file to integrate the components we created earlier.<\/p>\n<pre><code>import React, { useState } from 'react';\nimport Header from '.\/Header';\nimport DiaryList from '.\/DiaryList';\nimport DiaryEntry from '.\/DiaryEntry';\nimport '.\/App.css';\n\nfunction App() {\n    const [diaries, setDiaries] = useState([]);\n\n    const addDiary = (diary) => {\n        setDiaries([...diaries, { id: diaries.length + 1, ...diary }]);\n    };\n\n    return (\n        <div className=\"App\">\n            <Header \/>\n            <DiaryEntry onSubmit=\"{addDiary}\" \/>\n            <DiaryList diaries=\"{diaries}\" \/>\n        <\/div>\n    );\n}\n\nexport default App;<\/code><\/pre>\n<p>Now, the basic implementation of the diary app is complete. Users can enter a title and content to create diary entries and view the entries in a list.<\/p>\n<h2>7. Optimization<\/h2>\n<p>When building a React application, performance optimization is also important. Here are some optimization techniques:<\/p>\n<h3>7.1. React.memo<\/h3>\n<p>React components are re-rendered by default when props change. However, by using <code>React.memo<\/code>, you can prevent the component from re-rendering unless the props change.<\/p>\n<pre><code>const DiaryList = React.memo(({ diaries }) => {\n    \/\/ Component content\n});<\/code><\/pre>\n<h3>7.2. useCallback and useMemo<\/h3>\n<p>The <code>useCallback<\/code> hook memoizes functions so that the same function is returned unless the dependency array changes. <code>useMemo<\/code> memoizes computed values. This can help prevent unnecessary re-renders.<\/p>\n<pre><code>const addDiary = useCallback((diary) => {\n    setDiaries((prevDiaries) => [...prevDiaries, { id: prevDiaries.length + 1, ...diary }]);\n}, []);<\/code><\/pre>\n<h3>7.3. Lazy Loading<\/h3>\n<p>In React, you can use Lazy Loading through code splitting. This allows you to load components only when needed, improving initial load speed. You can utilize React&#8217;s <code>React.lazy<\/code> and <code>Suspense<\/code>.<\/p>\n<pre><code>const DiaryList = React.lazy(() => import('.\/DiaryList'));\n\nreturn (\n    <Suspense fallback=\"{<div>Loading...<\/div>}\">\n        <DiaryList diaries=\"{diaries}\" \/>\n    <\/Suspense>\n);<\/code><\/pre>\n<h2>8. Conclusion<\/h2>\n<p>In this tutorial, we created a basic diary app using React. We also discussed performance optimization techniques to explore more efficient ways of application development. When applying this code and optimization techniques to real projects, refer to them to create better-performing apps.<\/p>\n<p>React is an easy-to-learn and powerful tool. I hope you gain a deeper understanding by creating various applications. Happy Coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In recent years, React has established itself as one of the most popular libraries for web application development. With React, you can create fast, efficient, and reusable UI components. In this tutorial, we will examine how to create a simple diary app using React. Additionally, we will discuss performance optimization. 1. Project Setup Before getting &hellip; <a href=\"https:\/\/atmokpo.com\/w\/32927\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;React Course: Diary App Example and Optimization&#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-32927","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: Diary App Example and Optimization - \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\/32927\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"React Course: Diary App Example and Optimization - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"In recent years, React has established itself as one of the most popular libraries for web application development. With React, you can create fast, efficient, and reusable UI components. In this tutorial, we will examine how to create a simple diary app using React. Additionally, we will discuss performance optimization. 1. Project Setup Before getting &hellip; \ub354 \ubcf4\uae30 &quot;React Course: Diary App Example and Optimization&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/32927\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:12:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:21:26+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=\"3\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/32927\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32927\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"React Course: Diary App Example and Optimization\",\"datePublished\":\"2024-11-01T09:12:32+00:00\",\"dateModified\":\"2024-11-01T11:21:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32927\/\"},\"wordCount\":523,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"React basics course\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/32927\/\",\"url\":\"https:\/\/atmokpo.com\/w\/32927\/\",\"name\":\"React Course: Diary App Example and Optimization - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:12:32+00:00\",\"dateModified\":\"2024-11-01T11:21:26+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32927\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/32927\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/32927\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"React Course: Diary App Example and Optimization\"}]},{\"@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: Diary App Example and Optimization - \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\/32927\/","og_locale":"ko_KR","og_type":"article","og_title":"React Course: Diary App Example and Optimization - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"In recent years, React has established itself as one of the most popular libraries for web application development. With React, you can create fast, efficient, and reusable UI components. In this tutorial, we will examine how to create a simple diary app using React. Additionally, we will discuss performance optimization. 1. Project Setup Before getting &hellip; \ub354 \ubcf4\uae30 \"React Course: Diary App Example and Optimization\"","og_url":"https:\/\/atmokpo.com\/w\/32927\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:12:32+00:00","article_modified_time":"2024-11-01T11:21:26+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":"3\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/32927\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/32927\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"React Course: Diary App Example and Optimization","datePublished":"2024-11-01T09:12:32+00:00","dateModified":"2024-11-01T11:21:26+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/32927\/"},"wordCount":523,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["React basics course"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/32927\/","url":"https:\/\/atmokpo.com\/w\/32927\/","name":"React Course: Diary App Example and Optimization - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:12:32+00:00","dateModified":"2024-11-01T11:21:26+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/32927\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/32927\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/32927\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"React Course: Diary App Example and Optimization"}]},{"@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\/32927","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=32927"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32927\/revisions"}],"predecessor-version":[{"id":32928,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32927\/revisions\/32928"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=32927"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=32927"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=32927"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}