{"id":32857,"date":"2024-11-01T09:12:01","date_gmt":"2024-11-01T09:12:01","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=32857"},"modified":"2024-11-01T11:21:43","modified_gmt":"2024-11-01T11:21:43","slug":"react-course-destructuring-assignment","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/32857\/","title":{"rendered":"React Course: Destructuring Assignment"},"content":{"rendered":"<p>React is a very popular library for modern web application development. It is important to deeply understand and efficiently utilize React&#8217;s API. In this course, we will take a closer look at <strong>Destructuring Assignment<\/strong> in particular. Destructuring Assignment is a feature introduced in ES6 (ECMAScript 2015) that allows you to easily extract values from arrays or objects. It helps you write more intuitive and readable code during React development.<\/p>\n<h2>What is Destructuring Assignment?<\/h2>\n<p>Destructuring Assignment is a syntax in JavaScript that allows you to easily access data from arrays or objects and assign it to variables. By using this feature, you can reduce repetitive code and write cleaner, more readable code.<\/p>\n<h3>Array Destructuring Assignment<\/h3>\n<p>With array destructuring assignment, you can easily assign elements of an array to variables. Here is an example for illustration.<\/p>\n<pre><code>const fruits = ['apple', 'banana', 'cherry'];\nconst [firstFruit, secondFruit] = fruits;\n\nconsole.log(firstFruit); \/\/ apple\nconsole.log(secondFruit); \/\/ banana\n<\/code><\/pre>\n<p>The above code assigns the first and second elements of the &#8216;fruits&#8217; array to the &#8216;firstFruit&#8217; and &#8216;secondFruit&#8217; variables, respectively. This allows you to easily extract the needed values without directly using the array indices.<\/p>\n<h3>Object Destructuring Assignment<\/h3>\n<p>You can also use destructuring assignment with objects. This method is particularly useful when dealing with props or state in React.<\/p>\n<pre><code>const person = {\n  name: 'John',\n  age: 30,\n  profession: 'developer'\n};\n\nconst { name, age } = person;\n\nconsole.log(name); \/\/ John\nconsole.log(age); \/\/ 30\n<\/code><\/pre>\n<p>In the above example, we extracted the &#8216;name&#8217; and &#8216;age&#8217; properties from the &#8216;person&#8217; object as variables. This allows for shorter and cleaner code.<\/p>\n<h2>Destructuring Assignment in React<\/h2>\n<p>In React, destructuring assignment allows for effective management of state and props. This process is very useful when writing components.<\/p>\n<h3>Functional Component and Destructuring Assignment<\/h3>\n<p>Let&#8217;s look at how to use destructuring assignment for props in a React Functional Component.<\/p>\n<pre><code>const Greeting = ({ name, age }) =&gt; {\n  return &lt;h1&gt;Hello, {name}. You are {age} years old.&lt;\/h1&gt;;\n};\n\nconst App = () =&gt; {\n  return &lt;Greeting name=\"Alice\" age={25} \/&gt;;\n};\n<\/code><\/pre>\n<p>In the above code, the <code>Greeting<\/code> component receives &#8216;name&#8217; and &#8216;age&#8217; passed via props using destructuring assignment and outputs their values. This approach improves code readability and clearly shows which props are being used.<\/p>\n<h3>State Management and Destructuring Assignment<\/h3>\n<p>Destructuring assignment is also very useful when using the state in React. Let&#8217;s examine how to manage state through the following example.<\/p>\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  return (\n    &lt;div&gt;\n      &lt;h2&gt;Count: {count}&lt;\/h2&gt;\n      &lt;button onClick={increment}&gt;Increment&lt;\/button&gt;\n    &lt;\/div&gt;\n  );\n};\n<\/code><\/pre>\n<p>The above code uses the <code>useState<\/code> hook to manage state. With destructuring assignment, we can easily use &#8216;count&#8217; and &#8216;setCount&#8217; as variables.<\/p>\n<h3>Nested Destructuring Assignment<\/h3>\n<p>Destructuring assignment can also be applied to nested objects. For example, consider the following object.<\/p>\n<pre><code>const userProfile = {\n  user: {\n    name: 'Bob',\n    age: 28,\n    location: 'USA'\n  },\n  active: true\n};\n\nconst { user: { name, age }, active } = userProfile;\n\nconsole.log(name); \/\/ Bob\nconsole.log(age); \/\/ 28\nconsole.log(active); \/\/ true\n<\/code><\/pre>\n<p>Using the above method, you can easily extract desired variables from nested structures.<\/p>\n<h2>Advantages of Destructuring Assignment<\/h2>\n<p>Destructuring assignment has several advantages.<\/p>\n<ul>\n<li><strong>Improved readability:<\/strong> The code becomes more concise and easier to understand.<\/li>\n<li><strong>Reduced repetitive code:<\/strong> The need to access the same object properties multiple times is decreased.<\/li>\n<li><strong>Explicit property usage:<\/strong> It clearly indicates which data is being used.<\/li>\n<\/ul>\n<h2>Disadvantages of Destructuring Assignment<\/h2>\n<p>Destructuring assignment is not always advantageous. In certain cases, there may be disadvantages.<\/p>\n<ul>\n<li><strong>Might need to modify existing code:<\/strong> You may have to modify existing code to apply the new syntax.<\/li>\n<li><strong>Performance concerns:<\/strong> In very large data structures, destructuring assignment may impact performance.<\/li>\n<\/ul>\n<h2>Practical Example<\/h2>\n<p>Based on the content discussed above, let&#8217;s create a simple React app. Below is an example of a component that displays a list of users.<\/p>\n<pre><code>import React from 'react';\n\nconst users = [\n  { id: 1, name: 'Alice', age: 25 },\n  { id: 2, name: 'Bob', age: 28 },\n  { id: 3, name: 'Charlie', age: 30 }\n];\n\nconst UserList = () =&gt; {\n  return (\n    &lt;ul&gt;\n      {users.map(({ id, name, age }) =&gt; (\n        &lt;li key={id}&gt;{name} is {age} years old.&lt;\/li&gt;\n      ))}\n    &lt;\/ul&gt;\n  );\n};\n\nconst App = () =&gt; {\n  return &lt;UserList \/&gt;;\n};\n<\/code><\/pre>\n<p>In this example, we iterate over the &#8216;users&#8217; array to output user information. We can easily extract the id, name, and age of each user using destructuring assignment.<\/p>\n<h2>Conclusion<\/h2>\n<p>Destructuring assignment is a powerful tool that significantly enhances the readability and maintainability of code in React development. You can especially feel its usefulness when dealing with props and state. If you learned the basic concepts of destructuring assignment and its applications in React through this course, it will greatly assist you in your future development. Make sure to actively utilize the various features of React to advance your web application development!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>React is a very popular library for modern web application development. It is important to deeply understand and efficiently utilize React&#8217;s API. In this course, we will take a closer look at Destructuring Assignment in particular. Destructuring Assignment is a feature introduced in ES6 (ECMAScript 2015) that allows you to easily extract values from arrays &hellip; <a href=\"https:\/\/atmokpo.com\/w\/32857\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;React Course: Destructuring Assignment&#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-32857","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: Destructuring Assignment - \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\/32857\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"React Course: Destructuring Assignment - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"React is a very popular library for modern web application development. It is important to deeply understand and efficiently utilize React&#8217;s API. In this course, we will take a closer look at Destructuring Assignment in particular. Destructuring Assignment is a feature introduced in ES6 (ECMAScript 2015) that allows you to easily extract values from arrays &hellip; \ub354 \ubcf4\uae30 &quot;React Course: Destructuring Assignment&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/32857\/\" \/>\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=\"4\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/32857\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32857\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"React Course: Destructuring Assignment\",\"datePublished\":\"2024-11-01T09:12:01+00:00\",\"dateModified\":\"2024-11-01T11:21:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32857\/\"},\"wordCount\":601,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"React basics course\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/32857\/\",\"url\":\"https:\/\/atmokpo.com\/w\/32857\/\",\"name\":\"React Course: Destructuring Assignment - \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\/32857\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/32857\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/32857\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"React Course: Destructuring Assignment\"}]},{\"@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: Destructuring Assignment - \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\/32857\/","og_locale":"ko_KR","og_type":"article","og_title":"React Course: Destructuring Assignment - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"React is a very popular library for modern web application development. It is important to deeply understand and efficiently utilize React&#8217;s API. In this course, we will take a closer look at Destructuring Assignment in particular. Destructuring Assignment is a feature introduced in ES6 (ECMAScript 2015) that allows you to easily extract values from arrays &hellip; \ub354 \ubcf4\uae30 \"React Course: Destructuring Assignment\"","og_url":"https:\/\/atmokpo.com\/w\/32857\/","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":"4\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/32857\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/32857\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"React Course: Destructuring Assignment","datePublished":"2024-11-01T09:12:01+00:00","dateModified":"2024-11-01T11:21:43+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/32857\/"},"wordCount":601,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["React basics course"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/32857\/","url":"https:\/\/atmokpo.com\/w\/32857\/","name":"React Course: Destructuring Assignment - \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\/32857\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/32857\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/32857\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"React Course: Destructuring Assignment"}]},{"@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\/32857","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=32857"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32857\/revisions"}],"predecessor-version":[{"id":32858,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32857\/revisions\/32858"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=32857"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=32857"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=32857"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}