This is expected behavior in React 18 when using Strict Mode in development.
React intentionally runs effects twice (setup → cleanup → setup) to help catch bugs with side effects and cleanup logic. In production, the effect runs only once.
You can read the official explanation here: My Effect runs twice when the component mounts.
If this causes issues, make sure your effect has a proper cleanup function.