Skip to content

Commit e4e05fc

Browse files
committed
Fix code warnings in App.js
1 parent 45842c3 commit e4e05fc

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/App.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import CostDisplay from './components/CostDisplay/CostDisplay';
22
import NumericDisplay from './components/NumericDisplay/NumericDisplay';
33
import './App.css';
4-
import { useState, useEffect } from 'react';
4+
import { useState, useEffect, useCallback } from 'react';
55
function App() {
66
//app component
77
const [points, setPoints] = useState(0); //set initial points to 0
@@ -11,6 +11,14 @@ function App() {
1111
const [clickMultiplier, setClickMultiplier] = useState(1);
1212
const [clickers, setClickers] = useState(1); //set clickers to 1
1313
const [seconds, setSeconds] = useState(0); //set initial seconds played to 0
14+
const updateClickers = useCallback(() => {
15+
//update click multiplier for clickers
16+
setClickMultiplier(clickers); //set click multiplier
17+
}, [clickers]);
18+
const updateAutoClickers = useCallback(() => {
19+
//update points per second for autoclickers
20+
setPointsPerSecond(autoClickers); //set points per second
21+
}, [autoClickers]);
1422
useEffect(() => {
1523
const interval = setInterval(() => {
1624
//increase points every second
@@ -23,6 +31,7 @@ function App() {
2331
clearInterval(interval); //clear interval when component unmounts
2432
};
2533
}, [points, pointsPerSecond, seconds, updateAutoClickers, updateClickers]);
34+
2635
function checkPointsForUpgrade(points, pointsRequired) {
2736
//check if user has enough points to upgrade
2837
if (pointsRequired !== 0 && points >= pointsRequired) {
@@ -33,14 +42,7 @@ function App() {
3342
return false;
3443
}
3544
}
36-
function updateClickers() {
37-
//update click multiplier for clickers
38-
setClickMultiplier(clickers); //set click multiplier
39-
}
40-
function updateAutoClickers() {
41-
//update points per second for autoclickers
42-
setPointsPerSecond(autoClickers); //set points per second
43-
}
45+
4446
function addPointsFromClick() {
4547
//add points from clicking a button
4648
setPoints(points + clickMultiplier); //increase points by 1 when button clicked

0 commit comments

Comments
 (0)