From a2bfcc48779cca4015295a897a5a97d3aa89f404 Mon Sep 17 00:00:00 2001 From: psong0808 Date: Thu, 8 Jun 2023 14:06:41 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B3=BC=EC=A0=9C1=20let=20=EC=A0=9C=EA=B1=B0?= =?UTF-8?q?=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/index.js b/src/index.js index bff95123..5d5f0f8f 100644 --- a/src/index.js +++ b/src/index.js @@ -1,2 +1,47 @@ /* eslint-disable react/react-in-jsx-scope, react/jsx-filename-extension */ /* @jsx createElement */ + +function createElement(tagName, props, ...children) { + const element = document.createElement(tagName); + + Object.entries(props || {}).forEach(([key, value]) => { + element[key.toLowerCase()] = value; + }); + children.flat().forEach((child) => { + if (child instanceof Node) { + element.appendChild(child); + return; + } + element.appendChild(document.createTextNode(child)); + }); + + return element; +} + +function render({ count }) { + function handleClick() { + render({ + count: count + 1, + }); + } + + const element = ( +
+

과제 1

+

+ {[1, 2, 3, 4, 5, 6, 7, 8, 9].map((i) => ( + + ))} +

+

+ {count} +

+
+ ); + document.getElementById('app').textContent = ''; + document.getElementById('app').appendChild(element); +} + +render({ + count: 0, +});