{"id":32929,"date":"2024-11-01T09:12:32","date_gmt":"2024-11-01T09:12:32","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=32929"},"modified":"2024-11-01T11:21:26","modified_gmt":"2024-11-01T11:21:26","slug":"react-course-diary-application-example-and-page-routing","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/32929\/","title":{"rendered":"React Course: Diary Application Example and Page Routing"},"content":{"rendered":"<p><body><\/p>\n<p>Hello! In this lesson, we will create a simple diary application using React. This application will implement features that allow users to write, save, and read their diaries. We will also learn how to structure various pages through page routing.<\/p>\n<h2>1. What is React?<\/h2>\n<p>React is a JavaScript library for building web applications. It focuses on building user interfaces and is designed to be component-based, making it highly reusable. React uses a virtual DOM to optimize performance and helps developers create dynamic web applications more easily.<\/p>\n<h2>2. Setting up the project environment<\/h2>\n<p>The first step in creating the diary application is to set up the development environment. Let&#8217;s use <code>create-react-app<\/code> to generate a basic template.<\/p>\n<pre><code>\nnpx create-react-app diary-app\ncd diary-app\nnpm start\n    <\/code><\/pre>\n<p>By executing the above commands, a React project will be created and a basic development server will start. Now, let&#8217;s install the necessary packages for the basic project.<\/p>\n<pre><code>\nnpm install react-router-dom\n    <\/code><\/pre>\n<h2>3. Designing the component structure<\/h2>\n<p>Now, let&#8217;s design the basic structure of the application. The diary application can consist of the following components:<\/p>\n<ul>\n<li><strong>Home<\/strong>: The main page that displays a list of previous diaries.<\/li>\n<li><strong>DiaryEntry<\/strong>: The page where users can write a diary.<\/li>\n<li><strong>DiaryDetail<\/strong>: The page that shows the details of the selected diary.<\/li>\n<\/ul>\n<h2>4. Implementing page routing<\/h2>\n<p>To create an application composed of multiple pages using React, we will implement routing using <code>react-router-dom<\/code>. First, let&#8217;s set up the router.<\/p>\n<pre><code>\nimport React from 'react';\nimport { BrowserRouter as Router, Route, Switch } from 'react-router-dom';\nimport Home from '.\/components\/Home';\nimport DiaryEntry from '.\/components\/DiaryEntry';\nimport DiaryDetail from '.\/components\/DiaryDetail';\n\nfunction App() {\n    return (\n        <Router>\n            <Switch>\n                <Route component=\"{Home}\" exact path=\"\/\"><\/Route>\n                <Route component=\"{DiaryEntry}\" path=\"\/entry\"><\/Route>\n                <Route component=\"{DiaryDetail}\" path=\"\/diary\/:id\"><\/Route>\n            <\/Switch>\n        <\/Router>\n    );\n}\n\nexport default App;\n    <\/code><\/pre>\n<h2>5. Implementing components<\/h2>\n<h3>Home Component<\/h3>\n<p>The Home component is the page where users can view their previous diaries. It provides a link to write a new diary along with the diary list.<\/p>\n<pre><code>\nimport React from 'react';\nimport { Link } from 'react-router-dom';\n\nfunction Home() {\n    return (\n        <div>\n            <h2>Diary<\/h2>\n            <Link to=\"\/entry\">Write a new diary<\/Link>\n            {\/* Add the diary list here *\/}\n        <\/div>\n    );\n}\n\nexport default Home;\n    <\/code><\/pre>\n<h3>DiaryEntry Component<\/h3>\n<p>The DiaryEntry component is the page where a user writes a new diary. Users can input a title and content, and when they click the save button, the diary is saved.<\/p>\n<pre><code>\nimport React, { useState } from 'react';\n\nfunction DiaryEntry() {\n    const [title, setTitle] = useState('');\n    const [content, setContent] = useState('');\n\n    const handleSubmit = (e) => {\n        e.preventDefault();\n        \/\/ Logic to save the diary\n        console.log({ title, content });\n    };\n\n    return (\n        <div>\n            <h2>Write a Diary<\/h2>\n            <form onSubmit={handleSubmit}>\n                <input placeholder=\"Title\" type=\"text\" value={title} onChange={(e) => setTitle(e.target.value)} required \/>\n                <textarea placeholder=\"Content\" value={content} onChange={(e) => setContent(e.target.value)} required \/>\n                <button type=\"submit\">Save<\/button>\n            <\/form>\n        <\/div>\n    );\n}\n\nexport default DiaryEntry;\n    <\/code><\/pre>\n<h3>DiaryDetail Component<\/h3>\n<p>The DiaryDetail component is the page that shows the detailed content of the selected diary. It displays the diary&#8217;s title, content, and other metadata.<\/p>\n<pre><code>\nimport React from 'react';\nimport { useParams } from 'react-router-dom';\n\nfunction DiaryDetail() {\n    const { id } = useParams();\n    \n    \/\/ Logic to fetch diary data corresponding to the id is needed here.\n\n    return (\n        <div>\n            <h2>Diary Detail (ID: {id})<\/h2>\n            {\/* Output diary content here *\/}\n        <\/div>\n    );\n}\n\nexport default DiaryDetail;\n    <\/code><\/pre>\n<h2>6. Saving and loading data<\/h2>\n<p>To save the diary written by the user, state management is needed. In this example, we will implement data saving simply using React&#8217;s state. For more complex applications, it is advisable to use Redux or Context API for state management.<\/p>\n<h3>Managing diary data<\/h3>\n<pre><code>\nimport React, { useState } from 'react';\n\n\/\/ Manage diary data in the App component.\nfunction App() {\n    const [diaries, setDiaries] = useState([]);\n    \n    const addDiary = (diary) => {\n        setDiaries([...diaries, diary]);\n    };\n\n    return (\n        <Router>\n            <DiaryContext.Provider value={{ diaries, addDiary }}>\n                <Switch>\n                    <Route component=\"{Home}\" exact path=\"\/\"><\/Route>\n                    <Route component=\"{DiaryEntry}\" path=\"\/entry\"><\/Route>\n                    <Route component=\"{DiaryDetail}\" path=\"\/diary\/:id\"><\/Route>\n                <\/Switch>\n            <\/DiaryContext.Provider>\n        <\/Router>\n    );\n}\n    <\/code><\/pre>\n<h2>7. Conclusion<\/h2>\n<p>In this lesson, we explored how to create a diary application using React and implement page routing. With React&#8217;s component structure and data management, it is easy to add various features and facilitate smoother interactions with users.<\/p>\n<p>Based on the example above, you can add more diverse functions. For example, you can add features to edit or delete diaries or introduce user authentication to expand it into a personal diary.<\/p>\n<h2>8. Additional study materials<\/h2>\n<p>To better understand React, please refer to the following materials:<\/p>\n<ul>\n<li><a href=\"https:\/\/reactjs.org\/docs\/getting-started.html\">Official React Documentation<\/a><\/li>\n<li><a href=\"https:\/\/reactrouter.com\/web\/guides\/quick-start\">React Router Guide<\/a><\/li>\n<li><a href=\"https:\/\/redux.js.org\/introduction\/getting-started\">Official Redux Documentation<\/a><\/li>\n<\/ul>\n<h2>9. Questions and Answers<\/h2>\n<p>If you have any questions about this lesson, please leave a comment. I hope this can be a place for us to think and grow together!<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello! In this lesson, we will create a simple diary application using React. This application will implement features that allow users to write, save, and read their diaries. We will also learn how to structure various pages through page routing. 1. What is React? React is a JavaScript library for building web applications. It focuses &hellip; <a href=\"https:\/\/atmokpo.com\/w\/32929\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;React Course: Diary Application Example and Page Routing&#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-32929","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 Application Example and Page Routing - \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\/32929\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"React Course: Diary Application Example and Page Routing - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Hello! In this lesson, we will create a simple diary application using React. This application will implement features that allow users to write, save, and read their diaries. We will also learn how to structure various pages through page routing. 1. What is React? React is a JavaScript library for building web applications. It focuses &hellip; \ub354 \ubcf4\uae30 &quot;React Course: Diary Application Example and Page Routing&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/32929\/\" \/>\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\/32929\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32929\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"React Course: Diary Application Example and Page Routing\",\"datePublished\":\"2024-11-01T09:12:32+00:00\",\"dateModified\":\"2024-11-01T11:21:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32929\/\"},\"wordCount\":491,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"React basics course\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/32929\/\",\"url\":\"https:\/\/atmokpo.com\/w\/32929\/\",\"name\":\"React Course: Diary Application Example and Page Routing - \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\/32929\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/32929\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/32929\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"React Course: Diary Application Example and Page Routing\"}]},{\"@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 Application Example and Page Routing - \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\/32929\/","og_locale":"ko_KR","og_type":"article","og_title":"React Course: Diary Application Example and Page Routing - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Hello! In this lesson, we will create a simple diary application using React. This application will implement features that allow users to write, save, and read their diaries. We will also learn how to structure various pages through page routing. 1. What is React? React is a JavaScript library for building web applications. It focuses &hellip; \ub354 \ubcf4\uae30 \"React Course: Diary Application Example and Page Routing\"","og_url":"https:\/\/atmokpo.com\/w\/32929\/","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\/32929\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/32929\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"React Course: Diary Application Example and Page Routing","datePublished":"2024-11-01T09:12:32+00:00","dateModified":"2024-11-01T11:21:26+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/32929\/"},"wordCount":491,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["React basics course"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/32929\/","url":"https:\/\/atmokpo.com\/w\/32929\/","name":"React Course: Diary Application Example and Page Routing - \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\/32929\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/32929\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/32929\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"React Course: Diary Application Example and Page Routing"}]},{"@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\/32929","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=32929"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32929\/revisions"}],"predecessor-version":[{"id":32930,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32929\/revisions\/32930"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=32929"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=32929"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=32929"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}