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

Remains 0 #7

Closed
kaibara opened this issue Jan 8, 2019 · 5 comments
Closed

Remains 0 #7

kaibara opened this issue Jan 8, 2019 · 5 comments
Assignees
Labels
feat feature project

Comments

@kaibara
Copy link
Owner

kaibara commented Jan 8, 2019

Issue

https://www.useloom.com/share/43bd30dc0f0741f7b09c63a3728d2ba9

@kaibara kaibara added the feat feature project label Jan 8, 2019
@kaibara kaibara self-assigned this Jan 8, 2019
@kaibara
Copy link
Owner Author

kaibara commented Jan 28, 2019

@kaibara
Copy link
Owner Author

kaibara commented Jan 28, 2019

this.setState({ input: event.target.value });

これでは、文字列の結合を行っている。
計算できるようにするためには、

this.setState({ input: +(event.target.value) });

または

this.setState({ input: Number(event.target.value) });

を使用する。

@kaibara
Copy link
Owner Author

kaibara commented Jan 28, 2019

以前の状態を保存するなら、Setstateを利用する。

this.setState(prevState => ({ sum: prevState.sum + prevState.input }));

@kaibara
Copy link
Owner Author

kaibara commented Jan 28, 2019

inputに初期値を入れることを忘れない。

state = {input:0};
<input value={this.state.input}>

@kaibara
Copy link
Owner Author

kaibara commented Jan 28, 2019

@kaibara kaibara closed this as completed Jan 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat feature project
Projects
None yet
Development

No branches or pull requests

1 participant