Skip to content

Fix Bugs1#1

Open
rustyneuron01 wants to merge 2 commits into
mainfrom
resolve-bug-1
Open

Fix Bugs1#1
rustyneuron01 wants to merge 2 commits into
mainfrom
resolve-bug-1

Conversation

@rustyneuron01
Copy link
Copy Markdown
Owner

No description provided.

Comment thread src/App.tsx Outdated
const lightDurations = [1000, 2000, 4000];

function App() {
const [activeColor, setActiveColor] = useState<number>(0);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about naming firstLightColor, and secondLightColor? That might improve the readability a lot.

Comment thread src/App.tsx Outdated

useEffect(() => {
const timer = setTimeout(() => {
setActiveColor((activeColor + 1) % 3);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment thread src/Components/Light/index.tsx Outdated
}

import "./index.css";
const Light = (props: LightProps) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about destructuring props instead of specifying it everytime?

Comment thread src/Components/TrafficLight/index.tsx Outdated
const [activeColor, setActiveColor] = useState<number>(props.initTurnOnLightNumber);
return (
<div className="traffic-light__box">
<Light color={LightColors.Red} isActive={activeColor === 0} />
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

activeColor is number? Why not enum here?

Comment thread src/models/LightColors.ts Outdated
@@ -0,0 +1,6 @@
export enum LightColors {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LightColor would make more sense

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants