{"id":32913,"date":"2024-11-01T09:12:26","date_gmt":"2024-11-01T09:12:26","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=32913"},"modified":"2024-11-01T11:21:30","modified_gmt":"2024-11-01T11:21:30","slug":"react-course-diary-app-example-implementing-the-new-page","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/32913\/","title":{"rendered":"React Course: Diary App Example &#8211; Implementing the New Page"},"content":{"rendered":"<p><body><\/p>\n<article>\n<header>\n<p>Author: [Author Name] | Date: [Date]<\/p>\n<\/header>\n<section>\n<h2>Introduction<\/h2>\n<p>React is a JavaScript library for building user interfaces. In this tutorial, we will cover the process of creating a diary app using React. We will implement the app&#8217;s &#8220;New&#8221; page, where users can create and save a new diary entry. This tutorial will provide detailed explanations of the basic concepts of React, including component design, state management, and event handling.<\/p>\n<\/section>\n<section>\n<h2>Prerequisites<\/h2>\n<p>To follow this tutorial, you will need the following prior knowledge:<\/p>\n<ul>\n<li>Basic understanding of HTML and CSS<\/li>\n<li>Basic syntax of JavaScript<\/li>\n<li>Basic concepts of React (components, props, state, etc.)<\/li>\n<\/ul>\n<p>Additionally, you must have Node.js and npm installed, and know how to start a project using create-react-app.<\/p>\n<\/section>\n<section>\n<h2>Setting Up the Project<\/h2>\n<p>First, create a new React project. Open your terminal and enter the following command to create a project using create-react-app:<\/p>\n<pre><code>npx create-react-app diary-app<\/code><\/pre>\n<p>Once the project is created, navigate to the folder and run the development server:<\/p>\n<pre><code>cd diary-app\nnpm start<\/code><\/pre>\n<p>Your basic React app should now be running. Next, we will install the necessary dependencies. Since we will be using React Router, enter the following command to install it:<\/p>\n<pre><code>npm install react-router-dom<\/code><\/pre>\n<\/section>\n<section>\n<h2>Setting Up the Router<\/h2>\n<p>To set up the router, open the <code>src\/App.js<\/code> file and add the following code:<\/p>\n<pre><code>import React from 'react';\nimport { BrowserRouter as Router, Route, Switch } from 'react-router-dom';\nimport Home from '.\/components\/Home';\nimport NewEntry from '.\/components\/NewEntry';\n\nfunction App() {\n    return (\n        <Router>\n            <Switch>\n                <Route component={Home} exact path=\"\/\"><\/Route>\n                <Route component={NewEntry} path=\"\/new\"><\/Route>\n            <\/Switch>\n        <\/Router>\n    );\n}\n\nexport default App;<\/code><\/pre>\n<p>In the code above, we defined two routes. The <code>Home<\/code> component is rendered at the &#8216;\/&#8217; path, and the <code>NewEntry<\/code> component is rendered at the &#8216;\/new&#8217; path.<\/p>\n<\/section>\n<section>\n<h2>Creating the NewEntry Component<\/h2>\n<p>Now, to implement the page for writing a new diary entry, create the <code>src\/components\/NewEntry.js<\/code> file and write the following code:<\/p>\n<pre><code>import React, { useState } from 'react';\n\nfunction NewEntry() {\n    const [title, setTitle] = useState('');\n    const [content, setContent] = useState('');\n\n    const handleSubmit = (e) => {\n        e.preventDefault();\n        \/\/ Add diary saving logic here\n        console.log('Title:', title);\n        console.log('Content:', content);\n    };\n\n    return (\n        <div>\n            <h2>Create New Diary Entry<\/h2>\n            <form onSubmit={handleSubmit}>\n                <div>\n                    <label>Title:<\/label>\n                    <input type=\"text\" value={title} onChange={(e) => setTitle(e.target.value)} \/>\n                <\/div>\n                <div>\n                    <label>Content:<\/label>\n                    <textarea value={content} onChange={(e) => setContent(e.target.value)}><\/textarea>\n                <\/div>\n                <button type=\"submit\">Save<\/button>\n            <\/form>\n        <\/div>\n    );\n}\n\nexport default NewEntry;<\/code><\/pre>\n<p>The code above manages the title and content as state, and logs to the console when the form is submitted. Now it&#8217;s time to add the diary saving logic.<\/p>\n<\/section>\n<section>\n<h2>Adding Diary Saving Logic<\/h2>\n<p>The diary saving logic can be implemented in various ways. Let&#8217;s take a look at a simple method to save it in local storage. Add the following code in the <code>handleSubmit<\/code> function of the <code>NewEntry<\/code> component:<\/p>\n<pre><code>const handleSubmit = (e) => {\n    e.preventDefault();\n\n    const newEntry = { title, content, date: new Date() };\n    let entries = JSON.parse(localStorage.getItem('entries')) || [];\n    entries.push(newEntry);\n    localStorage.setItem('entries', JSON.stringify(entries));\n\n    \/\/ Reset\n    setTitle('');\n    setContent('');\n};<\/code><\/pre>\n<p>With this, when the user writes a diary entry and clicks the save button, the new diary entry will be stored in local storage. We have reset the state to allow the user to easily write the next diary entry.<\/p>\n<\/section>\n<section>\n<h2>Checking the Results<\/h2>\n<p>Now let&#8217;s write a new diary entry and check the saved content. We can update the <code>Home<\/code> component to display the list of saved diary entries. Open the <code>src\/components\/Home.js<\/code> file and write the following code:<\/p>\n<pre><code>import React, { useEffect, useState } from 'react';\n\nfunction Home() {\n    const [entries, setEntries] = useState([]);\n\n    useEffect(() => {\n        const storedEntries = JSON.parse(localStorage.getItem('entries')) || [];\n        setEntries(storedEntries);\n    }, []);\n\n    return (\n        <div>\n            <h2>Diary Entries<\/h2>\n            <ul>\n                {entries.map((entry, index) => (\n                    <li key={index}>\n                        <h3>{entry.title}<\/h3>\n                        <p>{entry.content}<\/p>\n                        <small>{entry.date}<\/small>\n                    <\/li>\n                ))}\n            <\/ul>\n        <\/div>\n    );\n}\n\nexport default Home;<\/code><\/pre>\n<p>Now, the list of diary entries created by the user will be displayed on the home page. You will be able to see the diary titles, content, and the date as well.<\/p>\n<\/section>\n<section>\n<h2>Adding Styling<\/h2>\n<p>To make the React app more polished, let&#8217;s add some CSS styles. Open the <code>src\/App.css<\/code> file and add the following styles:<\/p>\n<pre><code>body {\n    font-family: Arial, sans-serif;\n    background-color: #f4f4f4;\n    margin: 0;\n    padding: 20px;\n}\n\nh1, h2, h3 {\n    color: #333;\n}\n\nform {\n    background: #fff;\n    padding: 20px;\n    border-radius: 5px;\n    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);\n}\n\ninput, textarea {\n    width: 100%;\n    padding: 10px;\n    margin: 10px 0;\n    border: 1px solid #ccc;\n    border-radius: 5px;\n}\n\nbutton {\n    padding: 10px 15px;\n    background: #28a745;\n    color: #fff;\n    border: none;\n    border-radius: 5px;\n    cursor: pointer;\n}\n\nbutton:hover {\n    background: #218838;\n}<\/code><\/pre>\n<p>Now the overall design of the app has improved, providing a user-friendly experience.<\/p>\n<\/section>\n<section>\n<h2>Conclusion<\/h2>\n<p>In this tutorial, we explored in detail how to implement the &#8220;New&#8221; page of a diary app using React. We provided basic functionalities for users to write and save new diary entries, allowing them to learn about component structure and state management concepts in React. Additionally, we also learned how to save data using local storage and style using CSS.<\/p>\n<p>We hope you think about adding more advanced features and expanding the app in the future. Use React&#8217;s capabilities to create your own amazing projects!<\/p>\n<\/section>\n<footer>\n<p>Author: [Author Name] | [Contact Information]<\/p>\n<\/footer>\n<\/article>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Author: [Author Name] | Date: [Date] Introduction React is a JavaScript library for building user interfaces. In this tutorial, we will cover the process of creating a diary app using React. We will implement the app&#8217;s &#8220;New&#8221; page, where users can create and save a new diary entry. This tutorial will provide detailed explanations of &hellip; <a href=\"https:\/\/atmokpo.com\/w\/32913\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;React Course: Diary App Example &#8211; Implementing the New Page&#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-32913","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 - Implementing the New Page - \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\/32913\/\" \/>\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 - Implementing the New Page - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Author: [Author Name] | Date: [Date] Introduction React is a JavaScript library for building user interfaces. In this tutorial, we will cover the process of creating a diary app using React. We will implement the app&#8217;s &#8220;New&#8221; page, where users can create and save a new diary entry. This tutorial will provide detailed explanations of &hellip; \ub354 \ubcf4\uae30 &quot;React Course: Diary App Example &#8211; Implementing the New Page&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/32913\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:12:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:21:30+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\/32913\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32913\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"React Course: Diary App Example &#8211; Implementing the New Page\",\"datePublished\":\"2024-11-01T09:12:26+00:00\",\"dateModified\":\"2024-11-01T11:21:30+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32913\/\"},\"wordCount\":563,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"React basics course\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/32913\/\",\"url\":\"https:\/\/atmokpo.com\/w\/32913\/\",\"name\":\"React Course: Diary App Example - Implementing the New Page - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:12:26+00:00\",\"dateModified\":\"2024-11-01T11:21:30+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32913\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/32913\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/32913\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"React Course: Diary App Example &#8211; Implementing the New Page\"}]},{\"@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 - Implementing the New Page - \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\/32913\/","og_locale":"ko_KR","og_type":"article","og_title":"React Course: Diary App Example - Implementing the New Page - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Author: [Author Name] | Date: [Date] Introduction React is a JavaScript library for building user interfaces. In this tutorial, we will cover the process of creating a diary app using React. We will implement the app&#8217;s &#8220;New&#8221; page, where users can create and save a new diary entry. This tutorial will provide detailed explanations of &hellip; \ub354 \ubcf4\uae30 \"React Course: Diary App Example &#8211; Implementing the New Page\"","og_url":"https:\/\/atmokpo.com\/w\/32913\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:12:26+00:00","article_modified_time":"2024-11-01T11:21:30+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\/32913\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/32913\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"React Course: Diary App Example &#8211; Implementing the New Page","datePublished":"2024-11-01T09:12:26+00:00","dateModified":"2024-11-01T11:21:30+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/32913\/"},"wordCount":563,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["React basics course"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/32913\/","url":"https:\/\/atmokpo.com\/w\/32913\/","name":"React Course: Diary App Example - Implementing the New Page - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:12:26+00:00","dateModified":"2024-11-01T11:21:30+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/32913\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/32913\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/32913\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"React Course: Diary App Example &#8211; Implementing the New Page"}]},{"@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\/32913","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=32913"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32913\/revisions"}],"predecessor-version":[{"id":32914,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32913\/revisions\/32914"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=32913"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=32913"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=32913"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}