Fix Bugs1#1
Open
rustyneuron01 wants to merge 2 commits into
Open
Conversation
| const lightDurations = [1000, 2000, 4000]; | ||
|
|
||
| function App() { | ||
| const [activeColor, setActiveColor] = useState<number>(0); |
There was a problem hiding this comment.
How about naming firstLightColor, and secondLightColor? That might improve the readability a lot.
|
|
||
| useEffect(() => { | ||
| const timer = setTimeout(() => { | ||
| setActiveColor((activeColor + 1) % 3); |
There was a problem hiding this comment.
You're creating a new timer whenever activeColor is changed. If you want to read the state without adding it to dependency, you can do like
setState(prevState => prevState + 1)
| } | ||
|
|
||
| import "./index.css"; | ||
| const Light = (props: LightProps) => { |
There was a problem hiding this comment.
How about destructuring props instead of specifying it everytime?
| const [activeColor, setActiveColor] = useState<number>(props.initTurnOnLightNumber); | ||
| return ( | ||
| <div className="traffic-light__box"> | ||
| <Light color={LightColors.Red} isActive={activeColor === 0} /> |
There was a problem hiding this comment.
activeColor is number? Why not enum here?
| @@ -0,0 +1,6 @@ | |||
| export enum LightColors { | |||
There was a problem hiding this comment.
LightColor would make more sense
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.
No description provided.