{"id":32855,"date":"2024-11-01T09:12:01","date_gmt":"2024-11-01T09:12:01","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=32855"},"modified":"2024-11-01T11:21:43","modified_gmt":"2024-11-01T11:21:43","slug":"react-course-a-closer-look-at-object-data-types","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/32855\/","title":{"rendered":"React Course: A Closer Look at Object Data Types"},"content":{"rendered":"<p><body><\/p>\n<p>React is one of the JavaScript libraries, primarily used for building user interfaces. Understanding the object data type is a crucial part of learning React. The object data type is one of the basic data structures in JavaScript, widely used in React for managing state and props. In this article, we will start with the basic concepts of object data types and take a closer look at how they are utilized within React.<\/p>\n<h2>1. Basic Concepts of Object Data Type<\/h2>\n<p>In JavaScript, an object is a data structure composed of key-value pairs. Each key is a string, and the value can be another object, array, function, or a primitive data type (like strings or numbers). This relationship allows us to efficiently work with complex data.<\/p>\n<h3>1.1 Creating Objects<\/h3>\n<p>There are several ways to create objects; let\u2019s look at the two most common methods.<\/p>\n<pre><code>\/\/ Object literal method\nconst person = {\n    name: \"John Doe\",\n    age: 30,\n    isStudent: false\n};\n\n\/\/ Creating objects using constructor functions\nfunction Person(name, age) {\n    this.name = name;\n    this.age = age;\n    this.isStudent = false;\n}\n\nconst student = new Person(\"Kim Chul-soo\", 20);\n<\/code><\/pre>\n<h3>1.2 Properties and Methods of Objects<\/h3>\n<p>Objects can have properties and methods. Properties represent the state of the object, while methods define the actions the object can perform.<\/p>\n<pre><code>const car = {\n    brand: \"Hyundai\",\n    model: \"Kona\",\n    year: 2021,\n    start: function() {\n        console.log(\"The car has started.\");\n    }\n};\n\ncar.start(); \/\/ Output: The car has started.\n<\/code><\/pre>\n<h2>2. Utilization of Objects in React<\/h2>\n<p>In React, objects are frequently used to manage state and props. They allow for organized management of component data, enabling the effective construction of complex applications.<\/p>\n<h3>2.1 Component State<\/h3>\n<p>State represents the data of a component and is an important factor in determining the component\u2019s UI. State can be managed in object form.<\/p>\n<pre><code>import React, { useState } from 'react';\n\nfunction App() {\n    const [user, setUser] = useState({\n        name: \"John Doe\",\n        age: 30\n    });\n\n    return (\n        <div>\n            <h1>{user.name} is {user.age} years old.<\/h1>\n            <button onclick=\"{(() => setUser({ ...user, age: user.age + 1 }))}\">\n                Increase Age\n            <\/button>\n        <\/div>\n    );\n}\n<\/code><\/pre>\n<h3>2.2 Props<\/h3>\n<p>In React, Props are a way to pass data from a parent component to a child component. By utilizing objects, multiple values can be efficiently transmitted.<\/p>\n<pre><code>function UserProfile({ user }) {\n    return (\n        <div>\n            <h2>User Information<\/h2>\n            <p>Name: {user.name}<\/p>\n            <p>Age: {user.age}<\/p>\n        <\/div>\n    );\n}\n\nfunction App() {\n    const user = { name: \"Kim Chul-soo\", age: 25 };\n    \n    return <UserProfile user=\"{user}\"><\/UserProfile>;\n}\n<\/code><\/pre>\n<h2>3. Maintaining the Immutability of Objects<\/h2>\n<p>When managing state in React, it is crucial to maintain the immutability of objects. This helps prevent unexpected side effects and optimizes performance. When updating an object, a new object should always be created.<\/p>\n<h3>3.1 Ways to Maintain Immutability<\/h3>\n<p>The most common way to maintain immutability is to use the spread operator (&#8230;). This allows us to copy the previous state and update only the properties that need changing.<\/p>\n<pre><code>const [state, setState] = useState({ count: 0 });\n\nconst incrementCount = () => {\n    setState(prevState => ({ ...prevState, count: prevState.count + 1 }));\n};\n<\/code><\/pre>\n<h3>3.2 Using the Immer Library<\/h3>\n<p>Immer is a library that helps to easily manage immutability. With Immer, you can write code that looks like you are directly modifying the state, while it manages immutability internally.<\/p>\n<pre><code>import produce from 'immer';\n\nconst [state, setState] = useState({ count: 0 });\n\nconst incrementCount = () => {\n    setState(produce(draft => {\n        draft.count += 1;\n    }));\n};\n<\/code><\/pre>\n<h2>4. Example of Using Object Data Type<\/h2>\n<p>Now, let&#8217;s create a simple React application that utilizes the object data type. This application will receive user information and display it on the screen.<\/p>\n<pre><code>import React, { useState } from 'react';\n\nfunction App() {\n    const [user, setUser] = useState({ name: '', age: '' });\n\n    const handleInputChange = (e) => {\n        const { name, value } = e.target;\n        setUser(prevUser => ({ ...prevUser, [name]: value }));\n    };\n\n    return (\n        <div>\n            <h1>User Information Input<\/h1>\n            <input name=\"name\" onChange=\"{handleInputChange}\" placeholder=\"Enter your name\" type=\"text\" value=\"{user.name}\"\/>\n            <input name=\"age\" onChange=\"{handleInputChange}\" placeholder=\"Enter your age\" type=\"number\" value=\"{user.age}\"\/>\n            <h2>{user.name} is {user.age} years old.<\/h2>\n        <\/div>\n    );\n}\n\nexport default App;\n<\/code><\/pre>\n<h2>5. Summary<\/h2>\n<p>In this article, we have explored in detail how to use object data types in React. Objects are essential for managing state and props, and maintaining the immutability of objects is crucial for performance optimization. To utilize React more effectively, it is necessary to deepen our understanding of object data types. Going forward, engage with more React-related courses to learn various concepts and apply them in real applications.<\/p>\n<h2>6. References<\/h2>\n<ul>\n<li><a href=\"https:\/\/reactjs.org\/docs\/getting-started.html\">Official React Documentation<\/a><\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Object\">JavaScript Object Documentation<\/a><\/li>\n<li><a href=\"https:\/\/immerjs.github.io\/immer\/\">Immer Library<\/a><\/li>\n<\/ul>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>React is one of the JavaScript libraries, primarily used for building user interfaces. Understanding the object data type is a crucial part of learning React. The object data type is one of the basic data structures in JavaScript, widely used in React for managing state and props. In this article, we will start with the &hellip; <a href=\"https:\/\/atmokpo.com\/w\/32855\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;React Course: A Closer Look at Object Data Types&#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-32855","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: A Closer Look at Object Data Types - \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\/32855\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"React Course: A Closer Look at Object Data Types - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"React is one of the JavaScript libraries, primarily used for building user interfaces. Understanding the object data type is a crucial part of learning React. The object data type is one of the basic data structures in JavaScript, widely used in React for managing state and props. In this article, we will start with the &hellip; \ub354 \ubcf4\uae30 &quot;React Course: A Closer Look at Object Data Types&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/32855\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:12:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:21:43+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\/32855\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32855\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"React Course: A Closer Look at Object Data Types\",\"datePublished\":\"2024-11-01T09:12:01+00:00\",\"dateModified\":\"2024-11-01T11:21:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32855\/\"},\"wordCount\":479,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"React basics course\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/32855\/\",\"url\":\"https:\/\/atmokpo.com\/w\/32855\/\",\"name\":\"React Course: A Closer Look at Object Data Types - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:12:01+00:00\",\"dateModified\":\"2024-11-01T11:21:43+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32855\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/32855\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/32855\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"React Course: A Closer Look at Object Data Types\"}]},{\"@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: A Closer Look at Object Data Types - \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\/32855\/","og_locale":"ko_KR","og_type":"article","og_title":"React Course: A Closer Look at Object Data Types - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"React is one of the JavaScript libraries, primarily used for building user interfaces. Understanding the object data type is a crucial part of learning React. The object data type is one of the basic data structures in JavaScript, widely used in React for managing state and props. In this article, we will start with the &hellip; \ub354 \ubcf4\uae30 \"React Course: A Closer Look at Object Data Types\"","og_url":"https:\/\/atmokpo.com\/w\/32855\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:12:01+00:00","article_modified_time":"2024-11-01T11:21:43+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\/32855\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/32855\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"React Course: A Closer Look at Object Data Types","datePublished":"2024-11-01T09:12:01+00:00","dateModified":"2024-11-01T11:21:43+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/32855\/"},"wordCount":479,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["React basics course"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/32855\/","url":"https:\/\/atmokpo.com\/w\/32855\/","name":"React Course: A Closer Look at Object Data Types - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:12:01+00:00","dateModified":"2024-11-01T11:21:43+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/32855\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/32855\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/32855\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"React Course: A Closer Look at Object Data Types"}]},{"@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\/32855","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=32855"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32855\/revisions"}],"predecessor-version":[{"id":32856,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32855\/revisions\/32856"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=32855"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=32855"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=32855"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}