January 12, 2021
๊ทธ๊ฒ์ ๋ฐ๋ก ์ด ๊ธ์์ ๋ถํฐ..!
import React from 'react'
import { HashRouter as Router, Route } from 'react-router-dom'
import Home from '../routes/Home'
import Detail from '../routes/Detail'
const App = () => {
return (
<Router>
<Route path="/" exact component={Home}></Route>
<Route path="/:id" exact component={Detail}></Route>
</Router>
)
}
export default App
๋ฃจํธ ๊ฒฝ๋ก์์ ๋ณด์ฌ์ง๊ฒ ๋ ํฌ๋ ์ฑ์ ๊ทธ๋๋ก ๋ง๋ ๋ค?
๊ทธ๋ฅ Hooks, DOM ์ผ๋ก ์ถ๊ฐ๊น์ง ๋ง๋ ๋ค.
import React, { useState } from 'react'
const Home = () => {
const [text, setText] = useState('')
const handleChange = event => {
setText(event.target.value)
}
const handleSubmit = event => {
event.preventDefault()
// console.log(text);
const li = document.createElement('li')
const ul = document.querySelector('ul')
li.innerText = text
ul.appendChild(li)
setText('')
}
return (
<>
<h1>๐คSomething To Do๐ค</h1>
<form onSubmit={handleSubmit}>
<input type="text" value={text} onChange={handleChange} />
<button>Add</button>
</form>
<ul></ul>
</>
)
}
export default Home
์?
์ผ์ใ ใ ใ ใ ใ ใ
์ด์ ๋๋ต ๋๊ฐํด์ก๋ค.. gg..