-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreactClassComponent.tsx
More file actions
81 lines (71 loc) · 1.49 KB
/
reactClassComponent.tsx
File metadata and controls
81 lines (71 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import React, { Component } from "react";
type A = {
aa: string;
bb(x: number): string;
}["bb"];
interface J {
a(): void;
b: () => void;
}
interface P {
name: string;
title: string;
}
interface S {
word: string;
value: string;
result: string;
}
class WordRelay extends React.Component<P, S> {
state = {
word: "jyj",
value: "",
result: "",
};
onSubmitForm = (e: React.FormEvent) => {
e.preventDefault();
const input = this.input;
if (this.state.word[this.state.word.length - 1] === this.state.value[0]) {
this.setState({
result: "딩동댕",
word: this.state.value,
value: "",
});
if (input) {
input.focus();
}
} else {
this.setState({
result: "땡",
value: "",
});
if (input) {
input.focus();
}
}
};
onChangeInput = (e: React.ChangeEvent<HTMLInputElement>) => {
this.setState({ value: e.currentTarget.value });
};
input: HTMLInputElement | null = null; // this.input을 생성
onRefInput = (c: HTMLInputElement) => {
this.input = c;
};
render() {
return (
<>
<div>{this.state.word}</div>
<form onSubmit={this.onSubmitForm}>
<input
ref={this.onRefInput}
value={this.state.value}
onChange={this.onChangeInput}
/>
<button>클릭!!!</button>
</form>
<div>{this.state.result}</div>
</>
);
}
}
export default WordRelay;