Skip to content

Commit 79ef6a8

Browse files
🔥 Quick Hotfix - User Component refactor!
User Component is now fully stateless and the state is handled completely with @MOBX :)
1 parent bf605b9 commit 79ef6a8

File tree

1 file changed

+7
-33
lines changed

1 file changed

+7
-33
lines changed

src/components/user/user.jsx

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,8 @@ import Language from '../language/language';
66
// Stylesheet Imports
77
import './stylesheets/user.scss';
88

9-
@inject('user')
10-
@observer
11-
class User extends Component {
12-
constructor(props) {
13-
super(props);
14-
this.increaseXp = this.increaseXp.bind(this);
15-
this.changeName = this.changeName.bind(this);
16-
this.changeLastName = this.changeLastName.bind(this);
17-
}
18-
19-
increaseXp() {
20-
this.props.user.increaseXp(100);
21-
}
22-
23-
changeName() {
24-
this.props.user.changeName('John');
25-
}
26-
27-
changeLastName() {
28-
this.props.user.changeLastName('Doe');
29-
}
30-
31-
render() {
32-
const { fullName, age, xp } = this.props.user;
33-
return (
34-
<div id="user">
9+
const User = ({user, fullName, age, xp}) => (
10+
<div id="user">
3511
<div className="container">
3612
<div className="card">
3713
<div className="card-block">
@@ -46,28 +22,26 @@ class User extends Component {
4622
</p>
4723
<button
4824
className="d-block btn btn-primary"
49-
onClick={this.increaseXp}
25+
onClick={() => user.increaseXp(100)}
5026
>
5127
<Language resource="ACTIONS.INCREASE_XP" />
5228
</button>
5329
<button
5430
className="d-block btn btn-secondary"
55-
onClick={this.changeName}
31+
onClick={() => user.changeName('John')}
5632
>
5733
<Language resource="ACTIONS.CHANGE_NAME" />
5834
</button>
5935
<button
6036
className="d-block btn btn-secondary"
61-
onClick={this.changeLastName}
37+
onClick={() => user.changeLastName('Doe')}
6238
>
6339
<Language resource="ACTIONS.CHANGE_LASTNAME" />
6440
</button>
6541
</div>
6642
</div>
6743
</div>
6844
</div>
69-
);
70-
}
71-
}
45+
)
7246

73-
export default User;
47+
export default inject('user')(observer(User));

0 commit comments

Comments
 (0)