We can use useEffect function with an empty dependency array to run it once. Sometimes, we receive a warning (From ESLint) if we use it that way. To remove the warning we must add a comment.
When we have to use this in many places, it breaks the DRY (Don't Repeat Yourself) principle. Therefore, I have created a custom hook called useEffectOnce to handle it. This video explains how to implement that in a project.