holdanddeepdive / javascript-deep-dive

3 stars 1 forks source link

39장 DOM -> HTML attribute vs Dom property in react #40

Open hyunahOh opened 2 years ago

hyunahOh commented 2 years ago

리액트에서는 DOM을 어떻게 업데이트하는지 찍어봤습니다.

import { useState } from "react";
import "./App.css";

function App() {
  const [value, setValue] = useState("");

  const $inputElm = document.getElementById("input");

  /* HTML attributes */
  console.log("HTML attributes", $inputElm?.getAttribute("value"));
  /* DOM property */
  console.log("DOM property", $inputElm?.value);

  return (
    <div className="App">
      <input
        id="input"
        value={value}
        onChange={(e) => setValue(e.target.value)}
      />
    </div>
  );
}
image