MCPcopy Create free account
hub / github.com/coolvasanth/reactjs_interview_preparation / Exercise7

Function Exercise7

src/HardQuestions/Exercise7.js:3–21  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1import React, { useState, useEffect } from 'react';
2
3function Exercise7() {
4 const [count, setCount] = useState(0);
5
6 useEffect(() => {
7 const id = setInterval(() => {
8 setCount(prevCount => prevCount + 1);
9 }, 1000);
10
11 return () => clearInterval(id);
12 }, []);
13
14 useEffect(() => {
15 if (count === 5) {
16 clearInterval(id);
17 }
18 }, [count]);
19
20 return <h1>{count}</h1>;
21}
22
23export default Exercise7;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected