score:0
So basically the issue was that I was not correctly applying(or ignoring lint error
) this: //eslint-disable-next-line react-hooks/exhaustive-deps
I should have applied it above the last line of that useEffect hook.
The correct way to fix those kind of issues is this:
useEffect(() => {
if (isTimeRunning && timeRemaining > 0) {
setTimeout(() => {
setTimeRemaining((time) => time - 1);
}, 1000);
} else if (timeRemaining === 0) {
return endGame();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [timeRemaining, isTimeRunning]);
score:1
You shouldn't be calling the function when adding it to the dependencies, but rather you should pass the function reference.
Try this: [timeRemaining, isTimeRunning, endGame]
Source: stackoverflow.com
Related Query
- Getting react-hooks/exhaustive-deps error while trying to deploy a react app
- getting error while trying to deploy a React app to Azure App Service
- Trying to deploy React App to Azure using a Github Actions workflow but getting an error in TypeScript
- Trying to deploy my react app on Netlify which I created on a local host, but get an error while trying to deploy
- I'm getting error like this while creating react app
- Trying to deploy my React app with gh-pages but got this error message : The "file" argument must be of type string. Received type undefined
- Azure App Service Getting error while deploying REACT JS application
- Keep getting error while creating react app
- Getting an out of memory error while using Create React App and Plotly.js
- Getting an error that images is null while trying to show a preview of the uploaded images in react js
- Trying to deploy my REACT Webpack app to heroku. Everything works locally and the heroku build works. But I'm getting a 404 nginx
- Error "Cannot read property 'map' of undefined" while trying to read & display data from firestore via my react app
- Getting error while trying to render array of object in react js
- useParams getting 0 in console log but correct id in url while I am trying to edit in my curd react app
- getting an error while creating react app
- getting error while adding css to button in my react js app
- Error while trying to create react app using npm
- Trying to deploy react app on aws amplify but keep getting a "Base Directory not specified for artifacts, unable to create build artifact."
- Trying to deploy a React/Redux app to Heroku....now I'm getting an R14 memory error
- I keep getting this error while i try to use npm start on my react app
- I am trying to start a new react project But I am getting this error and the app is not created. I have installed react globally
- am getting an error props.onSubmitForm is not a function while trying to pass data from child to parent component in react
- I have been trying to install or create a react app but I kept getting this error message
- Dockercompose error while trying to npm start my react app
- Error getting while building react kotlin app using IntelliJ
- Getting error : "react-dom.production.min.js:216 TypeError: Object(...) is not a function" while deploying react app on github pages
- Building react app with docker while getting error at run npm install
- Getting Error while adding a component to App component of React
- While creating a react app I'm getting following error or errors
- Getting following error while deploying to node react app to heroku
More Query from same tag
- Video takes too much to load and play
- How to write test case for url push in useEffect react hook?
- React setState doesn't update
- Way to order data fetched by .data() firebase
- Material Design Lite with ReactJS (import/require Issue)
- Enabling CORS in Java Web Service
- Setting image opacity with styled-components
- Javascript Testing With Unique ID's
- OwlCarousel navigation for cards in left and right :react js
- Format JSON string to render in React component
- React | Multiple render
- How to stop sliding on last image of slider in carousel in bootstrap 5 on a reactjs project
- TypeError: Cannot read property 'contacts' of undefined
- How to organize typescript with mobx at ReactJS
- React can't set state with hooks in useEffect()
- using the map for getting the property to disable or not
- How to color text such that in black background it should be white, and in white bg text color should be black in css
- how to provide own image to svg for background?
- req.user and Is Authenticated always false
- How to pass props of one child component to another child component using parent component
- What is the best way to create a single MobX store for an app?
- React.Js - Part of the DOM does not render
- What is a react way to do this?
- Office UI Fabric React TagPicker new item
- how to remove comments in nested arrays using useReducer?
- React - Multiple components did update - why?
- object keeps resetting size into array after onClick
- No need to useEffect in this introductory sample code?
- Error during service worker registration: DOMException: Failed to register a ServiceWorker for scope.An SSL certificate error occurred
- State is not updated in StrictMode