Last active
June 2, 2021 18:13
-
-
Save ogwurujohnson/9c6edfae770e81d07d0ecad752c2c78f to your computer and use it in GitHub Desktop.
Converting class component to functional component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect } from 'react'; | |
function MyComponent({ fetchDrafts, fetchHistory }) { | |
useEffect(() => { | |
if (!fetchDrafts || !fetchHistory) { | |
return null | |
} | |
fetchDrafts(); | |
fetchHistory(); | |
const fetchDraftsTimer = setInterval(() => { | |
fetchDrafts(); | |
}, 120000); | |
return () => { | |
clearInterval(fetchDraftsTimer); | |
}; | |
}, []); | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That makes sense now. I thought removing the dependency array entirely would force it to run only once, this is my first time learning about this difference. Thanks will keep this in mind going forward.