Skip to content

과제1 let 제거하기 #207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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 = (
<div>
<h1>과제 1</h1>
<p>
{[1, 2, 3, 4, 5, 6, 7, 8, 9].map((i) => (
<button type="button" onClick={() => handleClick()}>{i}</button>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

          <button type="button" onClick={handleClick>{i}</button>

핸들러 함수 참조만 전달해도 좋겠네요 ㅎㅎ

))}
</p>
<p>
{count}
</p>
</div>
);
document.getElementById('app').textContent = '';
document.getElementById('app').appendChild(element);
}

render({
count: 0,
});