Skip to content

Commit d19acd5

Browse files
committed
converted to functional components
1 parent dbb3a5d commit d19acd5

File tree

4 files changed

+25
-69
lines changed

4 files changed

+25
-69
lines changed

src/App.css

-39
Original file line numberDiff line numberDiff line change
@@ -1,39 +0,0 @@
1-
.App {
2-
text-align: center;
3-
}
4-
5-
.App-logo {
6-
height: 40vmin;
7-
pointer-events: none;
8-
}
9-
10-
11-
@media (prefers-reduced-motion: no-preference) {
12-
.App-logo {
13-
animation: App-logo-spin infinite 20s linear;
14-
}
15-
}
16-
17-
.App-header {
18-
background-color: #282c34;
19-
min-height: 100vh;
20-
display: flex;
21-
flex-direction: column;
22-
align-items: center;
23-
justify-content: center;
24-
font-size: calc(10px + 2vmin);
25-
color: white;
26-
}
27-
28-
.App-link {
29-
color: #61dafb;
30-
}
31-
32-
@keyframes App-logo-spin {
33-
from {
34-
transform: rotate(0deg);
35-
}
36-
to {
37-
transform: rotate(360deg);
38-
}
39-
}

src/App.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import './App.css';
33
import { MainForm } from './Components/MainForm';
44

55
const App = () => (
6-
<MainForm message="Hello!"/>
6+
<MainForm />
77
);
88

99
export default App;

src/Components/TimeInput.jsx

+21-27
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,30 @@
1-
import React from "react";
1+
import React, { useState } from "react";
22
import Timer from "./Timer";
33

44
const defaultTimerDuration = "15";
55

6-
export default class TimeInput extends React.Component{
7-
8-
constructor(props){
9-
super(props);
10-
this.state = { value: defaultTimerDuration }
11-
this.handleChange = this.handleChange.bind(this);
12-
this.handleClick = this.handleClick.bind(this);
13-
}
14-
15-
handleChange(e){
16-
this.setState({ value: e.target.value })
6+
const TimeInput = () => {
7+
const [value, setValue] = useState(defaultTimerDuration)
8+
9+
const handleChange = (e) => {
10+
setValue(e.target.value)
1711
}
1812

19-
handleClick(e){
13+
const handleClick = (e) => {
2014
this.setState({ value: ""})
2115
}
16+
return (
17+
<div>
18+
<form>
19+
<input type="text" value={value}
20+
onChange={(e) => { setValue(e.target.value) }}
21+
onClick={(e) => { setValue(e.target.value) }}/>
22+
</form>
23+
<Timer duration={value}></Timer>
24+
</div>
25+
)
2226

23-
render(){
24-
return(
25-
<div>
26-
<form>
27-
<input type="text" value={this.state.value}
28-
onChange={this.handleChange}
29-
onClick={this.handleClick}
30-
ref={this.instanceRef} />
31-
</form>
32-
<Timer duration={this.state.value} /*clickHandler={this.handleBtnClick}*/ ></Timer>
33-
</div>
34-
)
35-
}
36-
}
27+
28+
}
29+
30+
export default TimeInput

src/Components/styles.css

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
.button{
66
width:100px;
7-
height:20px;
7+
height: 40px;
8+
border-radius: 5px;
89
display: inline-block;
9-
background-color: red;
10+
background-color: azure;
1011
}

0 commit comments

Comments
 (0)