Skip to content

Instantly share code, notes, and snippets.

@MeetMartin
Created September 11, 2021 01:12
Show Gist options
  • Save MeetMartin/3357f957f5e61eebbb276ab3e0e95187 to your computer and use it in GitHub Desktop.
Save MeetMartin/3357f957f5e61eebbb276ab3e0e95187 to your computer and use it in GitHub Desktop.
import React, { useEffect } from 'react';
const MyComponentWithInterval = () => {
useEffect(() => {
const myInterval = setInterval(() => {
console.log('Hello World');
}, 5000);
return () => clearInterval(myInterval);
}, []);
return (<p>We write Hello World into the consol every 5 seconds.</p>);
};
export default MyComponentWithInterval;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment