1week#53
Open
sooojinan wants to merge 3 commits into
Open
Conversation
yesjin-git
reviewed
Oct 27, 2019
| this.state = { | ||
| number: 0 | ||
| number: 0, | ||
| number2: 0 |
Owner
There was a problem hiding this comment.
number와 number2로 나누어 작성해주셨습니다. 잘 작성해주셨습니다.
다만 이런 고민을 해보면 좀 더 좋은 코드에 대해 생각해볼 수 있을 것 같습니다. 만약 카운터가 3개가 된다면, 각각의 함수들이 한개씩 더 늘어나게 됩니다. 이를 줄이려면 어떻게 해야할까요?
보다 근본적으로는 app 에서 모든 state를 갖고 있음으로 인해 발생하게되는 문제이기도 합니다. counter가 state를 갖게 하는 방식으로 해결방법을 고민해 봅시다.
yesjin-git
reviewed
Oct 27, 2019
| handleIncreaseDouble={this.handleIncreaseDouble} | ||
| handleDecreaseDouble={this.handleDecreaseDouble} | ||
| handleReset2={this.handleReset2} | ||
| number2={this.state.number2} |
Owner
There was a problem hiding this comment.
어차피 모든 함수들을 counter로 넘겨줄거라면, 애초에 보다 낮은 컴포넌트인 counter에서 각각의 함수들을 정의하는 것이 보다 직관적일 것 같습니다.
yesjin-git
reviewed
Oct 27, 2019
| <div>값: {this.props.number2}</div> | ||
| <button onClick={this.props.handleIncreaseDouble}>+</button> | ||
| <button onClick={this.props.handleDecreaseDouble}>-</button> | ||
| <button onClick={this.props.handleReset2}>reset</button> |
Owner
There was a problem hiding this comment.
카운터 1과 카운터 는 사실상 같은 일을 하지만, 늘어나는 숫자의 차이만 존재합니다. 이 두 컴포넌트간의 차이에 해당하는 부분만 props로 받도록 하고 나머지는 같은 컴포넌트를 사용하는 방식이 보다 효율적입니다.
예를들어 이런 방식으로요. 자세한 내용은 답지를 참고해주세요.
yesjin-git
reviewed
Oct 27, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
안수진
1Week homework