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.
Watch video useEffectOnce custom hook | React JS online, duration hours minute second in high quality that is uploaded to the channel Chiran Nuwan 18 November 2022. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 221 times and liked it 2 visitors.