{"id":32853,"date":"2024-11-01T09:12:00","date_gmt":"2024-11-01T09:12:00","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=32853"},"modified":"2024-11-01T11:21:44","modified_gmt":"2024-11-01T11:21:44","slug":"react-course-objects","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/32853\/","title":{"rendered":"React Course: Objects"},"content":{"rendered":"<p><body><\/p>\n<p>React is one of the most widely used libraries in modern web development and is very effective for building user interfaces. In this course, we will take a closer look at how to handle objects in React. Objects are one of the core concepts of JavaScript and play an important role in state management and data transfer in React.<\/p>\n<h2>1. What is an object?<\/h2>\n<p>An object is a data structure that includes properties and methods (functions). In JavaScript, objects are made up of key-value pairs enclosed in curly braces ({}). For example, you can create an object like this:<\/p>\n<pre><code>const person = {\n    name: 'John Doe',\n    age: 30,\n    greet: function() {\n        console.log(`Hello, I am ${this.name}!`);\n    }\n};<\/code><\/pre>\n<p>The above code creates an object called <code>person<\/code>, which includes properties like <code>name<\/code> and <code>age<\/code>. Additionally, you can output the object&#8217;s information to the console through a method called <code>greet<\/code>.<\/p>\n<h2>2. Utilization of objects<\/h2>\n<p>Objects can be used for various purposes in React. Here are a few examples of how to utilize objects in React components:<\/p>\n<h3>2.1 State management<\/h3>\n<p>When managing state in a React component, you can use objects. For example, you can define a state with multiple properties as an object:<\/p>\n<pre><code>import React, { useState } from 'react';\n\nconst UserProfile = () =&gt; {\n    const [user, setUser] = useState({\n        name: 'John Doe',\n        age: 30,\n        email: 'john@example.com'\n    });\n\n    const updateUserName = (newName) =&gt; {\n        setUser(prevUser =&gt; ({\n            ...prevUser,\n            name: newName\n        }));\n    };\n\n    return (\n        <div>\n            <h2>User Profile<\/h2>\n            <p>Name: {user.name}<\/p>\n            <p>Age: {user.age}<\/p>\n            <p>Email: {user.email}<\/p>\n            <button onclick=\"{()\"> updateUserName('Mike Lee')}&gt;Change Name<\/button>\n        <\/div>\n    );\n};<\/code><\/pre>\n<p>In the above example, we use <code>useState<\/code> to manage the <code>user<\/code> object as state. When changing the name, we call the <code>setUser<\/code> function to update the state.<\/p>\n<h3>2.2 Prop passing<\/h3>\n<p>When passing data between React components, you can utilize objects. Below is an example of passing an object from a parent component to a child component:<\/p>\n<pre><code>const ParentComponent = () =&gt; {\n    const user = {\n        name: 'John Doe',\n        age: 30\n    };\n\n    return <ChildComponent user=\"{user}\"><\/ChildComponent>;\n};\n\nconst ChildComponent = ({ user }) =&gt; {\n    return (\n        <div>\n            <h2>Child Component<\/h2>\n            <p>Name: {user.name}<\/p>\n            <p>Age: {user.age}<\/p>\n        <\/div>\n    );\n};<\/code><\/pre>\n<p>In the above code, the <code>ParentComponent<\/code> passes the <code>user<\/code> object to the <code>ChildComponent<\/code>. The child component can access this object through props.<\/p>\n<h2>3. Immutability of objects in React<\/h2>\n<p>In React, you need to maintain the immutability of objects when updating state. Instead of directly modifying the state, you should create a new object to update the state. This is an essential principle for React to detect state changes and perform efficient rendering.<\/p>\n<p>One way to maintain immutability is by using the spread operator (&#8230;). For example, when updating the state, you can copy the existing state and only modify the parts that need to be changed:<\/p>\n<pre><code>const updateUserAge = (newAge) =&gt; {\n    setUser(prevUser =&gt; ({\n        ...prevUser,\n        age: newAge\n    }));\n};<\/code><\/pre>\n<h2>4. Deep copy and shallow copy of objects<\/h2>\n<p>When copying objects in JavaScript, it is important to understand the difference between deep copy and shallow copy. Shallow copy only copies the top-level properties of the object, while shared references are made for nested objects. On the other hand, deep copy creates an entirely new copy that includes all nested objects.<\/p>\n<h3>4.1 Shallow copy<\/h3>\n<p>You can use <code>Object.assign<\/code> or the spread operator to perform shallow copies:<\/p>\n<pre><code>const original = { a: 1, b: { c: 2 } };\nconst shallowCopy = { ...original };\nshallowCopy.b.c = 3;\n\nconsole.log(original.b.c); \/\/ 3 (shared reference)<\/code><\/pre>\n<h3>4.2 Deep copy<\/h3>\n<p>To perform a deep copy, you can use <code>JSON.parse<\/code> and <code>JSON.stringify<\/code>:<\/p>\n<pre><code>const deepCopy = JSON.parse(JSON.stringify(original));\ndeepCopy.b.c = 3;\n\nconsole.log(original.b.c); \/\/ 2 (independent object)<\/code><\/pre>\n<h2>5. Rendering optimization with objects in React<\/h2>\n<p>There are several techniques for optimizing performance when using objects in React. Here are some methods to avoid unnecessary rendering and maintain optimal performance:<\/p>\n<h3>5.1 Optimization using React.memo<\/h3>\n<p>By using <code>React.memo<\/code>, you can prevent components from re-rendering unless the props change. This helps avoid unnecessary rendering and improves performance:<\/p>\n<pre><code>const ChildComponent = React.memo(({ user }) =&gt; {\n    return <div>Name: {user.name}<\/div>;\n});<\/code><\/pre>\n<h3>5.2 useCallback and useMemo<\/h3>\n<p>You can memoize functions using the <code>useCallback<\/code> hook, and memoize computed values using <code>useMemo<\/code>. This helps avoid unnecessary rendering caused by complex calculations or function creations:<\/p>\n<pre><code>const memoizedValue = useMemo(() =&gt; computeExpensiveValue(a, b), [a, b]);<\/code><\/pre>\n<h2>6. Object destructuring assignment<\/h2>\n<p>Destructuring assignment, introduced in ES6, allows you to easily extract the properties of an object into variables. It is useful when receiving props in React:<\/p>\n<pre><code>const { name, age } = user;<\/code><\/pre>\n<p>In React components, props can often be used through destructuring assignment:<\/p>\n<pre><code>const ChildComponent = ({ user: { name, age } }) =&gt; {\n        return (\n            <div>\n                <p>Name: {name}<\/p>\n                <p>Age: {age}<\/p>\n            <\/div>\n        );\n    };<\/code><\/pre>\n<h2>7. Objects and API communications<\/h2>\n<p>In React applications, API communication is necessary for fetching data. In this process, you can use objects to manage the data. The <code>fetch<\/code> API is commonly used:<\/p>\n<pre><code>import React, { useEffect, useState } from 'react';\n\nconst DataFetchingComponent = () =&gt; {\n    const [data, setData] = useState([]);\n\n    useEffect(() =&gt; {\n        const fetchData = async () =&gt; {\n            const response = await fetch('https:\/\/api.example.com\/data');\n            const result = await response.json();\n            setData(result);\n        };\n        fetchData();\n    }, []);\n\n    return (\n        <div>\n            {data.map((item) =&gt; (\n                <div key=\"{item.id}\">{item.name}<\/div>\n            ))}\n        <\/div>\n    );\n};<\/code><\/pre>\n<h2>8. Conclusion<\/h2>\n<p>In this course, we learned about various methods and concepts for handling objects in React. Objects play a core role in important aspects such as state management, data transfer, and API communications in React. With a solid understanding of objects, you can design and develop React applications more efficiently.<\/p>\n<p>By effectively utilizing immutability, deep copy and shallow copy, destructuring assignment, etc. when using React, you can optimize performance and improve code readability. I hope this will help you in your React development journey!<\/p>\n<footer>\n<p>Author: [Your Name]<\/p>\n<p>Blog: [Your Blog URL]<\/p>\n<\/footer>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>React is one of the most widely used libraries in modern web development and is very effective for building user interfaces. In this course, we will take a closer look at how to handle objects in React. Objects are one of the core concepts of JavaScript and play an important role in state management and &hellip; <a href=\"https:\/\/atmokpo.com\/w\/32853\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;React Course: Objects&#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-32853","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: Objects - \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\/32853\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"React Course: Objects - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"React is one of the most widely used libraries in modern web development and is very effective for building user interfaces. In this course, we will take a closer look at how to handle objects in React. Objects are one of the core concepts of JavaScript and play an important role in state management and &hellip; \ub354 \ubcf4\uae30 &quot;React Course: Objects&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/32853\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:12:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:21:44+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\/32853\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32853\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"React Course: Objects\",\"datePublished\":\"2024-11-01T09:12:00+00:00\",\"dateModified\":\"2024-11-01T11:21:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32853\/\"},\"wordCount\":655,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"React basics course\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/32853\/\",\"url\":\"https:\/\/atmokpo.com\/w\/32853\/\",\"name\":\"React Course: Objects - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:12:00+00:00\",\"dateModified\":\"2024-11-01T11:21:44+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32853\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/32853\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/32853\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"React Course: Objects\"}]},{\"@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: Objects - \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\/32853\/","og_locale":"ko_KR","og_type":"article","og_title":"React Course: Objects - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"React is one of the most widely used libraries in modern web development and is very effective for building user interfaces. In this course, we will take a closer look at how to handle objects in React. Objects are one of the core concepts of JavaScript and play an important role in state management and &hellip; \ub354 \ubcf4\uae30 \"React Course: Objects\"","og_url":"https:\/\/atmokpo.com\/w\/32853\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:12:00+00:00","article_modified_time":"2024-11-01T11:21:44+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\/32853\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/32853\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"React Course: Objects","datePublished":"2024-11-01T09:12:00+00:00","dateModified":"2024-11-01T11:21:44+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/32853\/"},"wordCount":655,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["React basics course"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/32853\/","url":"https:\/\/atmokpo.com\/w\/32853\/","name":"React Course: Objects - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:12:00+00:00","dateModified":"2024-11-01T11:21:44+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/32853\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/32853\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/32853\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"React Course: Objects"}]},{"@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\/32853","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=32853"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32853\/revisions"}],"predecessor-version":[{"id":32854,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32853\/revisions\/32854"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=32853"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=32853"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=32853"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}