File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
docs/engineering/javascript/react Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Using ` setTimeout ` in React Class Components
2
+
3
+ ``` javascript
4
+ class TimeoutWrapper extends Component {
5
+ constructor (props ) {
6
+ super (props);
7
+
8
+ // Initialise the timeout state
9
+ this .state = {
10
+ timeout: null
11
+ };
12
+ }
13
+
14
+ userTimeout () {
15
+ const { timeout } = this .state ;
16
+ // Clear any previous timeouts
17
+ clearTimeout (timeout);
18
+ // Set our new timeout
19
+ this .setState ({
20
+ timeout: setTimeout (() => {
21
+ // Do some fun timeout stuff here :)
22
+ }, 1000 )
23
+ });
24
+ }
25
+ }
26
+ ```
Original file line number Diff line number Diff line change 44
44
- " Debounce " : " engineering/javascript/snippets/debounce.md"
45
45
- React :
46
46
- " React DevTools " : " engineering/javascript/react/react-devtools.md"
47
+ - " React setTimeout " : " engineering/javascript/react/react-class-timeout.md"
47
48
- NPM :
48
49
- " NVM QuickStart " : " engineering/javascript/npm/nvm.md"
49
50
- " NPM Tips & Snippets " : " engineering/javascript/npm/npm-tips.md"
You can’t perform that action at this time.
0 commit comments