Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

clearing setInterval

const App = () => {
  const [loading, setLoading] = React.useState(true);
  React.useEffect(() => {
    const interval = setInterval(() => {
      setLoading(false);
    }, 3000);
    return () => clearInterval(interval);
  }, []);
  return (
    <div className="App">{loading ? <h1>Loading</h1> : <h2>Counter</h2>}</div>
  );
}
ReactDOM.render(<App />, document.getElementById("root"));
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #clearing #setInterval
ADD COMMENT
Topic
Name
2+3 =