Add MobX for state management

This commit is contained in:
Jan Tuomi
2018-06-20 12:54:44 +03:00
parent 71dbb2b58c
commit 04d6bd032a
12 changed files with 195 additions and 59 deletions
+21 -11
View File
@@ -1,18 +1,28 @@
import * as React from "react";
import { observer } from "mobx-react";
import "./App.scss";
const reactLogo = require("../../assets/img/react_logo.svg");
import appState from "../../stores/AppStore";
import Button from "../Button";
export interface AppProps {
appState: {
increment: () => string,
counter: number
};
}
export default class App extends React.Component<AppProps, undefined> {
render() {
return (
<div className="app__landing">
<h1>Aalto-yliopiston sähköinsinöörikilta!</h1>
<p>Sähköä, viinaa, naisia.</p>
</div>
);
}
@observer class App extends React.Component<AppProps, undefined> {
constructor(props) {
super(props);
}
render() {
return <div className="app__landing">
<h1>Aalto-yliopiston sähköinsinöörikilta!</h1>
<p>Sähköä, viinaa, naisia.</p>
<Button onClick={this.props.appState.increment}>{this.props.appState.counter}</Button>
</div>;
}
}
export default props => <App appState={appState} {...props} />;
+20
View File
@@ -0,0 +1,20 @@
@import "../../index.scss";
.button {
-webkit-appearance: none;
border-radius: none;
padding: 0.5rem 1rem;
margin: 0.5rem;
border: 2px solid $blue;
font-size: 1rem;
font-weight: 500;
&:hover {
border: 2px solid $dark-blue;
}
&:active,
&:focus {
outline: none;
}
}
+16
View File
@@ -0,0 +1,16 @@
import * as React from "react";
import "./Button.scss";
export interface ButtonProps {
onClick: () => void;
}
export default class Button extends React.Component<ButtonProps, undefined> {
render() {
return (
<button onClick={this.props.onClick} className="button">
{this.props.children}
</button>
);
}
}
+2
View File
@@ -0,0 +1,2 @@
import Button from "./Button";
export default Button;
+13
View File
@@ -0,0 +1,13 @@
import { observable, action } from "mobx";
import { observer } from "mobx-react";
class AppStore {
@observable counter = 0;
@action.bound
increment() {
this.counter += 1;
}
}
export default new AppStore();