Home.js 1.21 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 (
baesangjune's avatar
baesangjune committed
26
        <>
Jiwon Yoon's avatar
home    
Jiwon Yoon committed
27
28
29
30
31
32
33
            {done ? <Redirect to='/quiz' /> : ''}
            <div className="Box">
                <div className="Name"> 이름을 입력하세요
                <input onChange={handleChange} />
                </div>
                <div>
                    <button className="QuizStart" onClick={checking}>Quiz Start !</button>
baesangjune's avatar
baesangjune committed
34
                </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
35
            </div>
baesangjune's avatar
baesangjune committed
36
        </>
Jiwon Yoon's avatar
Jiwon Yoon committed
37
38
    )
}
baesangjune's avatar
baesangjune committed
39
40
41
42
43
44
45
46
function checking(event) {

    if (sessionStorage.getItem('name') === null||'') {
        alert('이름을 입력하세요')

        // alert('입력하신 이름은'+event.target+'입니다.')
    }
}
Jiwon Yoon's avatar
Jiwon Yoon committed
47

Jiwon Yoon's avatar
home    
Jiwon Yoon committed
48
49


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