Skip to content

Instantly share code, notes, and snippets.

@ifndefdeadmau5
Last active June 28, 2019 00:36
Show Gist options
  • Save ifndefdeadmau5/054a11c062a25b81bbbe94f5c5661ef9 to your computer and use it in GitHub Desktop.
Save ifndefdeadmau5/054a11c062a25b81bbbe94f5c5661ef9 to your computer and use it in GitHub Desktop.
Imperative.js
import React, { useState } from 'react';
import List from './List';
export default () => {
const [input, setInput] = useState('');
let todos = [];
return (
<div>
<input
type="text"
value={input}
onChange={event => setInput(event.target.value)}
/>
<button
onClick={() => {
todos = [...todos, input];
const listElement = document.getElementById('list');
const newTodo = document.createTextNode(input);
listElement.appendChild(newTodo)
}}
>
확인
</button>
<List id="list">
{todos}
</List>
</div>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment