{"id":32945,"date":"2024-11-01T09:12:39","date_gmt":"2024-11-01T09:12:39","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=32945"},"modified":"2024-11-01T11:21:22","modified_gmt":"2024-11-01T11:21:22","slug":"react-course-creating-a-counter-app-example-2","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/32945\/","title":{"rendered":"React Course: Creating a Counter App Example"},"content":{"rendered":"<p><body><\/p>\n<p>React is one of the most popular JavaScript libraries in modern web development. In this course, you will learn how to create a counter app using React. The counter app is a very simple project, but it is a great help in understanding and utilizing the basic concepts of React. The goals of this course are as follows:<\/p>\n<ul>\n<li>Understand the basic concepts of React<\/li>\n<li>Create and manage React components<\/li>\n<li>Understand state and props<\/li>\n<li>Implement event handling and state updates<\/li>\n<li>Develop applications using React<\/li>\n<\/ul>\n<h2>1. Preparing the Project<\/h2>\n<p>Before starting this counter app project, let&#8217;s organize the necessary preparations. You need to set up the basic environment needed for development.<\/p>\n<h3>1.1. Setting Up the Development Environment<\/h3>\n<p>To use React, you first need to install Node.js and npm (Node Package Manager). Node.js provides the JavaScript runtime environment, and npm is the tool for package management.<\/p>\n<ol>\n<li>Download Node.js: Download the installer from the <a href=\"https:\/\/nodejs.org\/en\/download\/\">official Node.js website<\/a> and install it.<\/li>\n<li>Check npm: After the installation is complete, check the installed versions of Node.js and npm with the following command:<\/li>\n<pre><code>node -v\nnpm -v<\/code><\/pre>\n<\/ol>\n<h3>1.2. Creating a New React Project<\/h3>\n<p>To create a React project, we will use a tool called Create React App. This automatically configures the initial setup for a React app. Use the following command to create a new React project:<\/p>\n<pre><code>npx create-react-app counter-app<\/code><\/pre>\n<p>After entering the command above, a folder named <em>counter-app<\/em> will be created, and the basic template for a React application will be set up. After completion, navigate to that folder:<\/p>\n<pre><code>cd counter-app<\/code><\/pre>\n<h3>1.3. Running the Development Server<\/h3>\n<p>After navigating to the project folder, you can run the development server with the following command:<\/p>\n<pre><code>npm start<\/code><\/pre>\n<p>When you enter this command, the React app will open in your default web browser at the address `http:\/\/localhost:3000`. Check if React is installed correctly through the initial screen.<\/p>\n<h2>2. Designing the Counter App<\/h2>\n<p>Now let&#8217;s briefly design the functionality and UI of the counter app. Essentially, this app allows users to increase or decrease the count by clicking a button.<\/p>\n<h3>2.1. Main Features<\/h3>\n<ul>\n<li>Button to increase the count<\/li>\n<li>Button to decrease the count<\/li>\n<li>Text displaying the current count<\/li>\n<li>Ability to set the initial count value<\/li>\n<\/ul>\n<h3>2.2. UI Design<\/h3>\n<p>The UI of the counter app is simple. It basically includes two buttons and a text to display the state. We&#8217;ll design the components through a basic HTML structure.<\/p>\n<h2>3. Implementing the Counter App<\/h2>\n<p>Now let&#8217;s actually implement the counter app. Create a file named <em>Counter.js<\/em> inside the src folder and write the component.<\/p>\n<h3>3.1. Creating the Counter Component<\/h3>\n<pre><code>import React, { useState } from 'react';\n\nconst Counter = () =&gt; {\n    const [count, setCount] = useState(0);\n\n    const increment = () =&gt; {\n        setCount(count + 1);\n    };\n\n    const decrement = () =&gt; {\n        setCount(count - 1);\n    };\n\n    return (\n        <div>\n            <h1>Current Count: {count}<\/h1>\n            <button onClick=\"{increment}\">Increase<\/button>\n            <button onClick=\"{decrement}\">Decrease<\/button>\n        <\/div>\n    );\n};\n\nexport default Counter;<\/code><\/pre>\n<p>The code above contains a React component with simple counter functionality. It uses the <em>useState<\/em> hook to manage the count state.<\/p>\n<h3>3.2. Adding the Counter Component to App.js<\/h3>\n<p>Now open the <em>App.js<\/em> file and add the Counter component. Modify the file as follows:<\/p>\n<pre><code>import React from 'react';\nimport Counter from '.\/Counter';\n\nfunction App() {\n    return (\n        <div className=\"App\">\n            <Counter><\/Counter>\n        <\/div>\n    );\n}\n\nexport default App;<\/code><\/pre>\n<h2>4. Adding Styling<\/h2>\n<p>Let&#8217;s add some styles to the counter app to make it look better. You can use a predefined CSS file or apply styles inline. Here we will use a CSS file for styling.<\/p>\n<h3>4.1. Creating the styles.css File<\/h3>\n<pre><code>body {\n    font-family: Arial, sans-serif;\n    text-align: center;\n}\n\nbutton {\n    margin: 10px;\n    padding: 10px 15px;\n    font-size: 16px;\n}<\/code><\/pre>\n<h3>4.2. Applying Styles<\/h3>\n<p>Now you can import and apply the styles in App.js:<\/p>\n<pre><code>import React from 'react';\nimport '.\/styles.css'; \/\/ Import new CSS file\nimport Counter from '.\/Counter';\n\nfunction App() {\n    return (\n        <div className=\"App\">\n            <Counter><\/Counter>\n        <\/div>\n    );\n}\n\nexport default App;<\/code><\/pre>\n<h2>5. Implementing Additional Features<\/h2>\n<p>The basic counter app is now complete. Next, let&#8217;s add the feature that allows users to set the initial count value.<\/p>\n<h3>5.1. Initial Count Setting Feature<\/h3>\n<pre><code>const Counter = () =&gt; {\n    const [count, setCount] = useState(0);\n    const [inputValue, setInputValue] = useState('');\n\n    const increment = () =&gt; {\n        setCount(count + 1);\n    };\n\n    const decrement = () =&gt; {\n        setCount(count - 1);\n    };\n\n    const setInitialCount = (e) =&gt; {\n        e.preventDefault();\n        setCount(Number(inputValue));\n        setInputValue('');\n    };\n\n    return (\n        <div>\n            <h1>Current Count: {count}<\/h1>\n            <input onChange=\"{(e) => setInputValue(e.target.value)}\" type=\"number\" value=\"{inputValue}\"\/>\n            <button onClick=\"{setInitialCount}\">Set Initial Value<\/button>\n            <button onClick=\"{increment}\">Increase<\/button>\n            <button onClick=\"{decrement}\">Decrease<\/button>\n        <\/div>\n    );\n};<\/code><\/pre>\n<p>In the code above, the <em>inputValue<\/em> state was added to allow the user to input a number. A button to set the initial value was added, and it applies the value to the count when clicked.<\/p>\n<h2>6. Conclusion and Deployment<\/h2>\n<p>The implementation of the counter app is complete. Now, we are ready to deploy the application. There are two basic methods: GitHub Pages and Vercel.<\/p>\n<h3>6.1. Deploying with GitHub Pages<\/h3>\n<ol>\n<li>Push the project to GitHub.<\/li>\n<li>Build the project with the following command:<\/li>\n<pre><code>npm run build<\/code><\/pre>\n<li>Host the generated build folder on GitHub Pages.<\/li>\n<\/ol>\n<h3>6.2. Deploying with Vercel<\/h3>\n<ol>\n<li>Sign up for Vercel and link your GitHub repository.<\/li>\n<li>Vercel will automatically deploy the project.<\/li>\n<\/ol>\n<h2>Conclusion<\/h2>\n<p>Through this course, you have learned the basic concepts of React and implemented a counter app. I hope this process has helped you understand state management, component creation, and event handling in React. Challenge yourself with more complex projects to improve your React skills!<\/p>\n<footer>\n<p>If you found this article useful, subscribe to the blog and check out other courses!<\/p>\n<\/footer>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>React is one of the most popular JavaScript libraries in modern web development. In this course, you will learn how to create a counter app using React. The counter app is a very simple project, but it is a great help in understanding and utilizing the basic concepts of React. The goals of this course &hellip; <a href=\"https:\/\/atmokpo.com\/w\/32945\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;React Course: Creating a Counter App Example&#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-32945","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: Creating a Counter App Example - \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\/32945\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"React Course: Creating a Counter App Example - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"React is one of the most popular JavaScript libraries in modern web development. In this course, you will learn how to create a counter app using React. The counter app is a very simple project, but it is a great help in understanding and utilizing the basic concepts of React. The goals of this course &hellip; \ub354 \ubcf4\uae30 &quot;React Course: Creating a Counter App Example&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/32945\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:12:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:21:22+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\/32945\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32945\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"React Course: Creating a Counter App Example\",\"datePublished\":\"2024-11-01T09:12:39+00:00\",\"dateModified\":\"2024-11-01T11:21:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32945\/\"},\"wordCount\":716,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"React basics course\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/32945\/\",\"url\":\"https:\/\/atmokpo.com\/w\/32945\/\",\"name\":\"React Course: Creating a Counter App Example - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:12:39+00:00\",\"dateModified\":\"2024-11-01T11:21:22+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32945\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/32945\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/32945\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"React Course: Creating a Counter App Example\"}]},{\"@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: Creating a Counter App Example - \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\/32945\/","og_locale":"ko_KR","og_type":"article","og_title":"React Course: Creating a Counter App Example - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"React is one of the most popular JavaScript libraries in modern web development. In this course, you will learn how to create a counter app using React. The counter app is a very simple project, but it is a great help in understanding and utilizing the basic concepts of React. The goals of this course &hellip; \ub354 \ubcf4\uae30 \"React Course: Creating a Counter App Example\"","og_url":"https:\/\/atmokpo.com\/w\/32945\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:12:39+00:00","article_modified_time":"2024-11-01T11:21:22+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\/32945\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/32945\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"React Course: Creating a Counter App Example","datePublished":"2024-11-01T09:12:39+00:00","dateModified":"2024-11-01T11:21:22+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/32945\/"},"wordCount":716,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["React basics course"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/32945\/","url":"https:\/\/atmokpo.com\/w\/32945\/","name":"React Course: Creating a Counter App Example - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:12:39+00:00","dateModified":"2024-11-01T11:21:22+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/32945\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/32945\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/32945\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"React Course: Creating a Counter App Example"}]},{"@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\/32945","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=32945"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32945\/revisions"}],"predecessor-version":[{"id":32946,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32945\/revisions\/32946"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=32945"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=32945"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=32945"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}