<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: yoriss67</title>
    <description>The latest articles on DEV Community by yoriss67 (@yoriss67).</description>
    <link>https://dev.to/yoriss67</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1109131%2Fb3f0b5ee-a741-4b74-8867-f2db5f406749.jpeg</url>
      <title>DEV Community: yoriss67</title>
      <link>https://dev.to/yoriss67</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yoriss67"/>
    <language>en</language>
    <item>
      <title>Beginner TypeScript: Vanilla&amp;React Comparison</title>
      <dc:creator>yoriss67</dc:creator>
      <pubDate>Mon, 17 Jul 2023 04:12:54 +0000</pubDate>
      <link>https://dev.to/yoriss67/beginner-typescript-vanillareact-comparison-2fhk</link>
      <guid>https://dev.to/yoriss67/beginner-typescript-vanillareact-comparison-2fhk</guid>
      <description>&lt;p&gt;I started TypeScript as many YouTubers and companies say it is in demand these days.&lt;/p&gt;

&lt;p&gt;Since I can understand English and Japanese, I used resources from both languages. &lt;br&gt;
So, in this post, I make a comparison to embark on a new journey of TypeScript as an absolute beginner🔰🛳️&lt;/p&gt;
&lt;h2&gt;
  
  
  Videos
&lt;/h2&gt;

&lt;p&gt;I used two YouTube videos, the first is WebDevSimplified.&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/jBmrduvKl5w"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;The second is プログラミングチュートリアル.&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/ANcopd8Bmao?start=666"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Although they have different approaches, they have the same "To-do List" project.&lt;br&gt;
So I tried if I could understand their differences and functionality.&lt;/p&gt;

&lt;p&gt;I really struggled to understand them by placing them on screen.&lt;br&gt;
The left is ①WebDevSimplified and the right is ②プログラミングチュートリアル.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cFyv7SXm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wd9xxeg7j1vl98d0hcj1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cFyv7SXm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wd9xxeg7j1vl98d0hcj1.png" alt="Image description" width="800" height="419"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Source code
&lt;/h2&gt;

&lt;p&gt;①　&lt;a href="https://github.com/WebDevSimplified/typescript-todo-list/tree/main"&gt;https://github.com/WebDevSimplified/typescript-todo-list/tree/main&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { v4 as uuidV4 } from "uuid"

type Task = {
  id: string
  title: string
  completed: boolean
  createdAt: Date
}

const list = document.querySelector&amp;lt;HTMLUListElement&amp;gt;("#list")
const form = document.getElementById("new-task-form") as HTMLFormElement | null
const input = document.querySelector&amp;lt;HTMLInputElement&amp;gt;("#new-task-title")
const tasks: Task[] = loadTasks()
tasks.forEach(addListItem)

form?.addEventListener("submit", e =&amp;gt; {
  e.preventDefault()

  if (input?.value == "" || input?.value == null) return

  const newTask: Task = {
    id: uuidV4(),
    title: input.value,
    completed: false,
    createdAt: new Date(),
  }
  tasks.push(newTask)
  saveTasks()

  addListItem(newTask)
  input.value = ""
})

function addListItem(task: Task) {
  const item = document.createElement("li")
  const label = document.createElement("label")
  const checkbox = document.createElement("input")
  checkbox.addEventListener("change", () =&amp;gt; {
    task.completed = checkbox.checked
    saveTasks()
  })
  checkbox.type = "checkbox"
  checkbox.checked = task.completed
  label.append(checkbox, task.title)
  item.append(label)
  list?.append(item)
}

function saveTasks() {
  localStorage.setItem("TASKS", JSON.stringify(tasks))
}

function loadTasks(): Task[] {
  const taskJSON = localStorage.getItem("TASKS")
  if (taskJSON == null) return []
  return JSON.parse(taskJSON)
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;②　&lt;a href="https://github.com/Shin-sibainu/todolist-react-typescript"&gt;https://github.com/Shin-sibainu/todolist-react-typescript&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState } from "react";
import "./App.css";

function App() {
  const [inputText, setInputText] = useState("");
  //todo配列オブジェクトの更新用に用意。プロパティはinputValue, id, checkedの３つを更新する。
  const [todos, setTodos] = useState&amp;lt;Todo[]&amp;gt;([]);

  type Todo = {
    inputValue: string;
    id: number; //keyを指定するため
    checked: boolean;
  };

  const handleChange = (e: React.ChangeEvent&amp;lt;HTMLInputElement&amp;gt;) =&amp;gt; {
    e.preventDefault();

    setInputText(e.target.value);
  };

  const handleSubmit = (e: { preventDefault: () =&amp;gt; void }) =&amp;gt; {
    e.preventDefault();

    if (!inputText) {
      return;
    }

    //新しいTodo作成
    const newTodo: Todo = {
      inputValue: inputText,
      id: todos.length,
      checked: false,
    };

    setTodos([newTodo, ...todos]);
    console.log(inputText);
    setInputText(inputText);
  };

  //todo編集　　　　　🤔①
  const handleEdit = (id: number, inputValue: string) =&amp;gt; {
    /* ディープコピー(完全にコピーされた別の配列)に変えよう(ミューテートから守るため) */　　　　🤔②
    const deepCopy = todos.map((todo) =&amp;gt; ({ ...todo }));
    console.log(deepCopy);
　　　　　　🤔③
    const newTodos = deepCopy.map((todo) =&amp;gt; {
      if (todo.id === id) {
        todo.inputValue = inputValue;
      }
      return todo;
    });

    // /* シャローコピー */
    // const newTodos = todos.map((todo) =&amp;gt; {
    //   if (todo.id === id) {
    //     todo.inputValue = inputValue;
    //   }
    //   return todo;
    // });

    setTodos(newTodos);
  };

  //完了未完了 
  const handleChecked = (id: number, checked: boolean) =&amp;gt; {
    /* ディープコピー(完全にコピーされた別の配列)に変えよう(ミューテートから守るため) */
    const deepCopy = todos.map((todo) =&amp;gt; ({ ...todo }));
    // console.log(deepCopy);

    const newTodos = deepCopy.map((todo) =&amp;gt; {
      if (todo.id === id) {
        //反転
        todo.checked = !checked;
      }
      return todo;
    });

    setTodos(newTodos);
  };

  //削除
  const handleDelete = (id: number) =&amp;gt; {
    //idが正しくないのは残す。正しいと消す。
    const newTodos = todos.filter((todo) =&amp;gt; todo.id !== id);
    setTodos(newTodos);
  };

  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;h2&amp;gt;Todoリスト with Typescript&amp;lt;/h2&amp;gt;
        &amp;lt;form onSubmit={(e) =&amp;gt; handleSubmit(e)}&amp;gt;
          &amp;lt;input
            type="text"
            onChange={(e) =&amp;gt; handleChange(e)}
            className="inputText"
          /&amp;gt;
          &amp;lt;input type="submit" value="作成" className="submitButton" /&amp;gt;
        &amp;lt;/form&amp;gt;
        {/* タスク設定が完了したら */}
        &amp;lt;ul className="todoList"&amp;gt;
          {todos.map((todo) =&amp;gt; (
            &amp;lt;li key={todo.id}&amp;gt;
              &amp;lt;input
                type="text"
                value={todo.inputValue}
                onChange={(e) =&amp;gt; handleEdit(todo.id, e.target.value)}
                disabled={todo.checked}
              /&amp;gt;
              &amp;lt;input
                type="checkbox"
                checked={todo.checked}
                onChange={() =&amp;gt; handleChecked(todo.id, todo.checked)}
              /&amp;gt;
              &amp;lt;button onClick={() =&amp;gt; handleDelete(todo.id)}&amp;gt;消&amp;lt;/button&amp;gt;
            &amp;lt;/li&amp;gt;
          ))}
        &amp;lt;/ul&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Thx ChatGPT!!!😭😭
&lt;/h2&gt;

&lt;p&gt;I got ChatGPT to make a table to compare them.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Aspect&lt;/th&gt;
&lt;th&gt;Folder 1 (WebDevSimplified)&lt;/th&gt;
&lt;th&gt;Folder 2 (React App)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Language&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;JavaScript/TypeScript&lt;/td&gt;
&lt;td&gt;TypeScript&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;UI Library/Framework&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;td&gt;React&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;State Management&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Local variables and local storage&lt;/td&gt;
&lt;td&gt;React &lt;code&gt;useState&lt;/code&gt; hook&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Type Definition&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The &lt;code&gt;Task&lt;/code&gt; type is defined with a type alias and used immediately.&lt;/td&gt;
&lt;td&gt;The &lt;code&gt;Todo&lt;/code&gt; type is defined with a type alias inside the component function.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Form Handling&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Uses traditional form and input handling with DOM APIs.&lt;/td&gt;
&lt;td&gt;Uses React's controlled components pattern with &lt;code&gt;useState&lt;/code&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Task/Todo Creation&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Creates a new task object and pushes it to the tasks array.&lt;/td&gt;
&lt;td&gt;Creates a new todo object and uses the &lt;code&gt;setTodos&lt;/code&gt; function to update state.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Task/Todo Editing&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Checkbox listener directly modifies the task's &lt;code&gt;completed&lt;/code&gt; property.&lt;/td&gt;
&lt;td&gt;Uses a &lt;code&gt;handleEdit&lt;/code&gt; function that creates a new array with the edited todo.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Task/Todo Completion&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Checkbox listener directly modifies the task's &lt;code&gt;completed&lt;/code&gt; property and saves to local storage.&lt;/td&gt;
&lt;td&gt;Uses a &lt;code&gt;handleChecked&lt;/code&gt; function that creates a new array with the toggled &lt;code&gt;checked&lt;/code&gt; property of the todo.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Task/Todo Deletion&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Not implemented.&lt;/td&gt;
&lt;td&gt;Uses a &lt;code&gt;handleDelete&lt;/code&gt; function that filters the todos array to exclude the deleted one.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Task/Todo Rendering&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Uses the &lt;code&gt;addListItem&lt;/code&gt; function to create and append HTML elements.&lt;/td&gt;
&lt;td&gt;Uses JSX to map over the todos array and render list items.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Data Persistence&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Uses &lt;code&gt;localStorage&lt;/code&gt; to persist tasks.&lt;/td&gt;
&lt;td&gt;Does not persist todos beyond the current session.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Where I didn't understand
&lt;/h2&gt;

&lt;h3&gt;
  
  
  🤔① What is “&lt;code&gt;?&lt;/code&gt;” and why there’s nothing after &lt;code&gt;return&lt;/code&gt; ?
&lt;/h3&gt;

&lt;p&gt;On line 19 of WebDevSimplified,&lt;br&gt;
&lt;code&gt;if (input?.value == "" || input?.value == null) return&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  As for &lt;code&gt;?&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;🙋‍♂️WebDevSimplified says&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;that's because when we do our query selector for our input right here&lt;br&gt;
 it's returning to us something that is either an html input element or something that is null.&lt;br&gt;
Because what if nothing with this id exists? &lt;br&gt;
Well, we need to take that into account typescript says hey this thing could be null so you need to take into account that it could be null.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But I couldn't get it well. So I asked ChatGPT.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🌸ChatGPT says&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Optional chaining: The video introduces optional chaining (?.) as a way to handle the possibility of null. Optional chaining is a way to tell TypeScript: "Hey, try to access this property or method, but if the object is null or undefined, just give me undefined immediately and don't throw an error." This is what the input?.value does in your code.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4&gt;
  
  
  As for &lt;code&gt;return&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;🌸ChatGPT says&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The line &lt;code&gt;if (input?.value == "" || input?.value == null) return&lt;/code&gt; is using what's known as an "early return" or a "guard clause". This is a common pattern in programming to stop the execution of a function if certain conditions are met.&lt;br&gt;
In this case, the function is stopped (i.e., it "returns") if the value of &lt;code&gt;input&lt;/code&gt; is either &lt;code&gt;null&lt;/code&gt;, &lt;code&gt;undefined&lt;/code&gt;, or an empty string (&lt;code&gt;""&lt;/code&gt;). This is to prevent the creation of a new task when the input is empty or invalid.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;🙋‍♀️So to summarize with my words, since TypeScript is more strict than normal js, we can let TypeScript think there is a possibility that the input might be &lt;code&gt;null&lt;/code&gt; or &lt;code&gt;undefined&lt;/code&gt;. If it is the case, TypeScript should return &lt;code&gt;undefined&lt;/code&gt; immediately and do nothing after that.&lt;/p&gt;
&lt;h3&gt;
  
  
  🤔② Which &lt;code&gt;id&lt;/code&gt; relates to which &lt;code&gt;id&lt;/code&gt; in プログラミングチュートリアル?
&lt;/h3&gt;

&lt;p&gt;On around line 41 of プログラミングチュートリアル,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  const handleEdit = (id: number, inputValue: string) =&amp;gt; {
    /* ディープコピー(完全にコピーされた別の配列)に変えよう(ミューテートから守るため) */
    const deepCopy = todos.map((todo) =&amp;gt; ({ ...todo }));
    console.log(deepCopy);

    const newTodos = deepCopy.map((todo) =&amp;gt; {
      if (todo.id === id) {
        todo.inputValue = inputValue;
      }
      return todo;
    });



~~~~~~

              &amp;lt;input
                type="text"
                value={todo.inputValue}
                onChange={(e) =&amp;gt; handleEdit(todo.id, e.target.value)}
                disabled={todo.checked}
              /&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I got confused how to understand which &lt;code&gt;id&lt;/code&gt; corresponds to which.😂So I asked ChatGPT to put emojis.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Define the Todo type
type Todo = {
  inputValue: string;
  id: number; // This id is the original source of both 🦥id and 🐼id.
  checked: boolean;
};

// Define the handleEdit function
const handleEdit = (🦥id: number, inputValue: string) =&amp;gt; {
  const deepCopy = todos.map((todo) =&amp;gt; ({ ...todo }));

  const newTodos = deepCopy.map((todo) =&amp;gt; {
    if (todo.🐼id === 🦥id) { // Compare the 'id' property of a Todo object to the 'id' argument of the function
      todo.inputValue = inputValue;
    }
    return todo;
  });

  setTodos(newTodos);
};

// Call the handleEdit function in the JSX
&amp;lt;input
  type="text"
  value={todo.inputValue}
  onChange={(e) =&amp;gt; handleEdit(todo.🦥id, e.target.value)} // Pass the 'id' property of the current Todo object as the first argument to the function
  disabled={todo.checked}
/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🌸ChatGPT says&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;🦥id: This is the argument to the &lt;strong&gt;&lt;code&gt;handleEdit&lt;/code&gt;&lt;/strong&gt; function. When the &lt;strong&gt;&lt;code&gt;handleEdit&lt;/code&gt;&lt;/strong&gt; function is called in the &lt;strong&gt;&lt;code&gt;onChange&lt;/code&gt;&lt;/strong&gt; event handler, the &lt;strong&gt;&lt;code&gt;id&lt;/code&gt;&lt;/strong&gt; property of the current &lt;strong&gt;&lt;code&gt;Todo&lt;/code&gt;&lt;/strong&gt; object is passed as this argument.&lt;/li&gt;
&lt;li&gt;🐼id: This is the &lt;strong&gt;&lt;code&gt;id&lt;/code&gt;&lt;/strong&gt; property of a &lt;strong&gt;&lt;code&gt;Todo&lt;/code&gt;&lt;/strong&gt; object. In the &lt;strong&gt;&lt;code&gt;handleEdit&lt;/code&gt;&lt;/strong&gt; function, this &lt;strong&gt;&lt;code&gt;id&lt;/code&gt;&lt;/strong&gt; is compared with the &lt;strong&gt;&lt;code&gt;🦥id&lt;/code&gt;&lt;/strong&gt; argument to find the &lt;strong&gt;&lt;code&gt;Todo&lt;/code&gt;&lt;/strong&gt; object that needs to be edited.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, when &lt;strong&gt;&lt;code&gt;handleEdit&lt;/code&gt;&lt;/strong&gt; is called with &lt;strong&gt;&lt;code&gt;todo.🦥id&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;e.target.value&lt;/code&gt;&lt;/strong&gt;, it maps over the &lt;strong&gt;&lt;code&gt;todos&lt;/code&gt;&lt;/strong&gt; array to create a new array. For each &lt;strong&gt;&lt;code&gt;Todo&lt;/code&gt;&lt;/strong&gt; object in the new array, if the &lt;strong&gt;&lt;code&gt;id&lt;/code&gt;&lt;/strong&gt; property of the &lt;strong&gt;&lt;code&gt;Todo&lt;/code&gt;&lt;/strong&gt; object (&lt;strong&gt;&lt;code&gt;todo.🐼id&lt;/code&gt;&lt;/strong&gt;) matches the &lt;strong&gt;&lt;code&gt;🦥id&lt;/code&gt;&lt;/strong&gt; argument, it updates the &lt;strong&gt;&lt;code&gt;inputValue&lt;/code&gt;&lt;/strong&gt; property of the &lt;strong&gt;&lt;code&gt;Todo&lt;/code&gt;&lt;/strong&gt; object to &lt;strong&gt;&lt;code&gt;e.target.value&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  🤔③ What is deep / shallow copy in プログラミングチュートリアル?
&lt;/h3&gt;

&lt;p&gt;Since it was the first time, I didn't understand general concepts in programming.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🌸ChatGPT says&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Shallow copy&lt;/strong&gt;: When you create a shallow copy of an object, you're creating a new object with the same properties, &lt;strong&gt;but&lt;/strong&gt; the property values are &lt;strong&gt;not duplicated.&lt;/strong&gt; This means that if a property value is an object or an array, the copy and the original will share the same reference to that object or array. If you modify the object or array through one of the references, the change will be visible when you access it through the other reference.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deep copy&lt;/strong&gt;: When you create a deep copy of an object, you're creating a new object with the same properties, and &lt;strong&gt;all the property values are also duplicated.&lt;/strong&gt; This means that the copy and the original have completely &lt;strong&gt;separate copies&lt;/strong&gt; of all data, including nested objects and arrays. Changes to one will &lt;strong&gt;not affect the other.&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  🤔④ Why do we need to make &lt;code&gt;const newTodos&lt;/code&gt; in プログラミングチュートリアル?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;🌸ChatGPT says&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The primary reason for creating &lt;code&gt;newTodos&lt;/code&gt; is to maintain the immutability of React's state.&lt;br&gt;
In React, you should not directly modify state. Instead of altering or updating an existing state object directly, you should generate a new state object and set that. This is a crucial part of how React detects changes to state and re-renders appropriately.&lt;br&gt;
For instance, when you want to change the &lt;code&gt;inputValue&lt;/code&gt; of a &lt;code&gt;Todo&lt;/code&gt;, instead of directly modifying it like this:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Don't do this!
todos[0].inputValue = "new value";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;You should create a new array of &lt;code&gt;Todo&lt;/code&gt;s, create a new &lt;code&gt;Todo&lt;/code&gt; object with the changes, and then set that as the state:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const newTodos = todos.map((todo) =&amp;gt; {
  if (todo.id === idToEdit) {
    return { ...todo, inputValue: "new value" };
  } else {
    return todo;
  }
});
setTodos(newTodos);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;So, &lt;code&gt;newTodos&lt;/code&gt; is used to create a new array with the changes applied, without directly modifying the original &lt;code&gt;todos&lt;/code&gt; array. This maintains the immutability of React's state, allowing React to properly detect changes to state and re-render.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Thank you for reading!
&lt;/h2&gt;

&lt;p&gt;I had a lot to learn, not only TypeScript, but also React and JavaScript concepts. I am never confident that I perfectly understand each code, but I'm happy that I made a progress🏋️🏋️‍♀️🏋️‍♂️&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>react</category>
      <category>beginners</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Japanese female International Studies student learns to code🗾👩‍🎓🌏👩‍💻</title>
      <dc:creator>yoriss67</dc:creator>
      <pubDate>Tue, 11 Jul 2023 09:42:42 +0000</pubDate>
      <link>https://dev.to/yoriss67/japanese-international-studies-student-learns-to-code-1gej</link>
      <guid>https://dev.to/yoriss67/japanese-international-studies-student-learns-to-code-1gej</guid>
      <description>&lt;p&gt;This is a quick introduction for myself.&lt;/p&gt;

&lt;p&gt;Hi, I’m Iori! I’m a college student and study frontend by myself.&lt;/p&gt;

&lt;p&gt;Since I have pretty much time as a student, I wanted to learn something practically useful for my career.&lt;br&gt;
The internet suggested me learn programming. I thought it would be advantageous even if I end up landing a non-geek job.&lt;/p&gt;

&lt;p&gt;I started a super popular Japanese programming site “Progate”. It’s like a game and really engaging.&lt;/p&gt;

&lt;p&gt;But I wanted English, so after I finish basic HTML, CSS and JS, I switched to English sources like freeCodeCamp, Udemy and YouTube.&lt;/p&gt;

&lt;p&gt;Before I start blogging here, I often uploaded my articles on note (Japanese very famous blog site 🫤NOT TECH HEAVY)&lt;br&gt;
&lt;a href="https://note.com/yoriss_b0607"&gt;https://note.com/yoriss_b0607&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I’m gonna locate my main blog habitant here from now!&lt;/p&gt;

&lt;p&gt;You can see my daily progress on Twitter as I post the record of the day almost everyday🦜📱&lt;br&gt;
&lt;a href="https://twitter.com/iori73wsy"&gt;https://twitter.com/iori73wsy&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you for reading! I am also happy to chat!&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>webdev</category>
      <category>codenewbie</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
