when the user visits the page and is already in dark mode the toggle switch remains in light mode and dont change the theme. If click twice it changes to light and then works normally.
This bug is due to react component mounting before the theme is checked.
To eliminate this useEffect would be fine with theme as dependency array, as useEffect only runs when the component is mounted.