Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Settled for remain 0 #10

Merged
merged 2 commits into from Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/Contents/Account.js
@@ -1,16 +1,16 @@
import React, { Fragment, Component } from "react"; import React, { Fragment, Component } from "react";


class Account extends Component { class Account extends Component {
state = { sum: 0 }; state = { sum: 0, input: 0 };
input = event => { input = event => {
this.setState({ input: event.target.value }); this.setState({ input: Number(event.target.value) });
console.log(this.state.input); console.log(this.state.input);
}; };
Plus = () => { Plus = () => {
this.setState({ sum: this.state.sum + this.state.input }); this.setState(prevState => ({ sum: this.state.sum + this.state.input }));
}; };
Main = () => { Minus = () => {
this.setState({ sum: this.state.sum - this.state.input }); this.setState(prevState => ({ sum: this.state.sum - this.state.input }));
}; };
render() { render() {
return ( return (
Expand All @@ -20,10 +20,10 @@ class Account extends Component {
現在:  現在: 
{this.state.sum} {this.state.sum}
</h3> </h3>
<input onChange={this.input} /> <input value={this.state.input} onChange={this.input} />
<br /> <br />
<button onClick={this.Plus}>収入</button> <button onClick={this.Plus}>収入</button>
<button onClick={this.Main}>支出</button> <button onClick={this.Minus}>支出</button>
</Fragment> </Fragment>
); );
} }
Expand Down
14 changes: 7 additions & 7 deletions src/Contents/Cache.js
@@ -1,16 +1,16 @@
import React, { Fragment, Component } from "react"; import React, { Fragment, Component } from "react";


class Cache extends Component { class Cache extends Component {
state = { sum: 0 }; state = { sum: 0, input: 0 };
input = event => { input = event => {
this.setState({ input: event.target.value }); this.setState({ input: Number(event.target.value) });
console.log(this.state.input); console.log(this.state.input);
}; };
Plus = () => { Plus = () => {
this.setState({ sum: this.state.sum + this.state.input }); this.setState(prevState => ({ sum: this.state.sum + this.state.input }));
}; };
Main = () => { Minus = () => {
this.setState({ sum: this.state.sum - this.state.input }); this.setState(prevState => ({ sum: this.state.sum - this.state.input }));
}; };
render() { render() {
return ( return (
Expand All @@ -20,10 +20,10 @@ class Cache extends Component {
現在:&nbsp; 現在:&nbsp;
{this.state.sum} {this.state.sum}
</h3> </h3>
<input onChange={this.input} /> <input value={this.state.input} onChange={this.input} />
<br /> <br />
<button onClick={this.Plus}>収入</button> <button onClick={this.Plus}>収入</button>
<button onClick={this.Main}>支出</button> <button onClick={this.Minus}>支出</button>
</Fragment> </Fragment>
); );
} }
Expand Down
14 changes: 7 additions & 7 deletions src/Contents/Card.js
@@ -1,16 +1,16 @@
import React, { Fragment, Component } from "react"; import React, { Fragment, Component } from "react";


class Card extends Component { class Card extends Component {
state = { sum: 0 }; state = { sum: 0, input: 0 };
input = event => { input = event => {
this.setState({ input: event.target.value }); this.setState({ input: Number(event.target.value) });
console.log(this.state.input); console.log(this.state.input);
}; };
Plus = () => { Plus = () => {
this.setState({ sum: this.state.sum + this.state.input }); this.setState(prevState => ({ sum: this.state.sum + this.state.input }));
}; };
Main = () => { Minus = () => {
this.setState({ sum: this.state.sum - this.state.input }); this.setState(prevState => ({ sum: this.state.sum - this.state.input }));
}; };
render() { render() {
return ( return (
Expand All @@ -20,10 +20,10 @@ class Card extends Component {
現在:&nbsp; 現在:&nbsp;
{this.state.sum} {this.state.sum}
</h3> </h3>
<input onChange={this.input} /> <input value={this.state.input} onChange={this.input} />
<br /> <br />
<button onClick={this.Plus}>収入</button> <button onClick={this.Plus}>収入</button>
<button onClick={this.Main}>支出</button> <button onClick={this.Minus}>支出</button>
</Fragment> </Fragment>
); );
} }
Expand Down