Skip to content

Commit 3ffc005

Browse files
committed
Lint & Modernize LabelsFilter.jsx
1 parent cdc73bd commit 3ffc005

File tree

1 file changed

+27
-31
lines changed

1 file changed

+27
-31
lines changed
Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,47 @@
1-
import React from 'react';
1+
import React, { useState } from "react";
22
import { connect } from "react-redux";
33
import { addLabel } from "../redux/actions";
44

55
const initialState = {
66
name: "",
7-
value: ""
8-
}
9-
class LabelsFilter extends React.Component {
10-
constructor(props) {
11-
super(props);
12-
this.state = initialState;
13-
}
14-
15-
updateCurrentLabel = (name) => {
16-
this.setState({ name });
17-
};
7+
value: "",
8+
};
189

19-
updateCurrentValue = (value) => {
20-
this.setState({ value });
10+
function LabelsFilter() {
11+
const [state, setState] = useState(initialState);
12+
const updateCurrentLabel = (name) => {
13+
setState({ name });
2114
};
22-
23-
addLabel = (e) => {
24-
this.props.addLabel(this.state.name, this.state.value);
25-
this.setState(initialState);
26-
e.preventDefault();
15+
const updateCurrentValue = (value) => {
16+
setState({ value });
2717
};
2818

29-
render() {
30-
return <form className="labels-new-label" onSubmit={this.addLabel}>
19+
return (
20+
<form className="labels-new-label" onSubmit={addLabel}>
3121
<input
3222
className="labels-new-input"
33-
onChange={(e) => this.updateCurrentLabel(e.target.value)}
23+
onChange={(e) => updateCurrentLabel(e.target.value)}
3424
placeholder="Name"
35-
value={this.state.name}
25+
value={state.name}
3626
/>
3727
<input
3828
className="labels-new-input"
39-
onChange={(e) => this.updateCurrentValue(e.target.value)}
29+
onChange={(e) => updateCurrentValue(e.target.value)}
4030
placeholder="Value"
41-
value={this.state.value}
31+
value={state.value}
4232
/>
43-
<button className="btn labels-new-btn" onClick={this.addLabel}>Add</button>
33+
<button
34+
className="btn labels-new-btn"
35+
onClick={(e) => {
36+
addLabel(state.name, state.value);
37+
setState(initialState);
38+
e.preventDefault();
39+
}}
40+
>
41+
Add
42+
</button>
4443
</form>
45-
}
44+
);
4645
}
4746

48-
export default connect(
49-
(x) => x,
50-
{ addLabel }
51-
)(LabelsFilter);
47+
export default connect((x) => x, { addLabel })(LabelsFilter);

0 commit comments

Comments
 (0)