Home.js 1.02 KB
Newer Older
Jiwon Yoon's avatar
home    
Jiwon Yoon committed
1
2
3
import React, { useState } from 'react'
import { Redirect } from 'react-router-dom';
// import { Link } from 'react-router-dom';
Jiwon Yoon's avatar
Jiwon Yoon committed
4
5
6


function Home() {
Jiwon Yoon's avatar
home    
Jiwon Yoon committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
    const [name, setName] = useState('')
    const [done, setDone] = useState(false)

    const handleChange = (event) => {
        setName(event.target.value)
    }

    function checking(event) {
        if (!name) {
            alert('이름을 입력하세요')
        }
        else {
            alert('입력하신 이름은' + name + '입니다.')
            localStorage.setItem('name', name)
            setDone(true)
        }
    }

Jiwon Yoon's avatar
Jiwon Yoon committed
25
    return (
Jiwon Yoon's avatar
home    
Jiwon Yoon committed
26
27
28
29
30
31
32
33
34
        <>
            {done ? <Redirect to='/quiz' /> : ''}
            <div className="Box">
                <div className="Name"> 이름을 입력하세요
                <input onChange={handleChange} />
                </div>
                <div>
                    <button className="QuizStart" onClick={checking}>Quiz Start !</button>
                </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
35
            </div>
Jiwon Yoon's avatar
home    
Jiwon Yoon committed
36
        </>
Jiwon Yoon's avatar
Jiwon Yoon committed
37
38
39
    )
}

Jiwon Yoon's avatar
home    
Jiwon Yoon committed
40
41


Jiwon Yoon's avatar
Jiwon Yoon committed
42
export default Home;