Skip to content
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

Fix: remove "let" #164

Merged
merged 3 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
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
57 changes: 57 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,59 @@
/* eslint-disable react/react-in-jsx-scope, react/jsx-filename-extension */
/* @jsx createElement */

// 미션 1. eslint 통과 -> 'render' was used before it was defined. 안 뜨게 하기.
// 미션 2. let을 써서 count 값을 재할당 하지 마라.

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;
}

const render = (count = 0) => {
function handleClick(value) {
render(value);
}

function handleClickNumber(value) {
render(value);
}

const element = (
<div id="hello" className="greeting">
<p>Hello, React!</p>
<p>
<button type="button" onClick={() => { handleClick(count + 1); }}>
Click me!
(
{count}
)
</button>
</p>
<p>
{[1, 2, 3].map((i) => (
<button type="button" onClick={() => handleClickNumber(i)}>
{i}
</button>
))}
</p>
</div>
);
const container = document.getElementById('app');
container.textContent = '';
container.appendChild(element);
};

render();
Loading