gaearon / gaearon/react-hot-loader
Modifying a functional component the uses setState hook
- Dominant language
- JavaScript
- Stars
- 12.2k
- Forks
- 775
- PR merge metrics
- No merged PRs in 30d
Description
Hey, I have this component:
```js
import React, { useState } from 'react';
const MyComponent = () => {
const [counter, setCounter] = useState(0);
setTimeout(() => {
setCounter(counter + 1);
}, 1000);
return (
{counter}
);
};
export default MyComponent;
```
When I modify setTimeout's body to:
```js
setCounter(counter + 10);
```
### Expected behavior
The counter will now increase by 10 every second.
### Actual behavior
The counter increases by 10 every second, but then, a few milliseconds later, in increases by 1 also.
### Environment
React Hot Loader version: 4.12.13
1. `node -v`: v10.15.1
2. `npm -v`: 6.4.1
1. Operating system: macOS 10.14.6
2. Browser and version: Chrome 76.0.3809.132
I went over all open issues and didn’t find anything regarding this. Might be something with my setup.
Contributor guide
Research direction
Start by reproducing the component shown in the issue with React Hot Loader 4.12.13, Node v10.15.1, and Chrome 76. Compare the setTimeout behavior for setCounter(counter + 1) and setCounter(counter + 10); done means identifying the cause of the extra increment and documenting a scoped change, since no repository file or test is named.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100