#how to properly use useEffect?
11 messages · Page 1 of 1 (latest)
🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord
🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize
✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)
not sure why its printing 6-12 times as well
suppose to be one only
This is for the sidebar, the "Controls" shows up late until the console prints "User is an admin" 5 times before actually showing it
It looks messy I know but it would be nice to teach on how to organize this type of stuffs
also did this on a layout this time because I am gate keeping it for admin users only
I'll come back to this tomorrow hoping someone answers
How many menu items do you have? Dev might render twice (might need to google). If you need current user in the entire app why not fetch it in parent as a server component and then pass as props.
I first would change the userAdmin state:
const [isUerAdmin, setIsUserAdmin] = useState<boolean>(false);
hooks value is boolean, so it would be convenient to name it isUserAdmin. there is no need for null either, have it false by default and then change it to the true. (if you don't need null in different logic)
Move the fetchUser outside the useEffect and replace fetchUser() with await fetchUser()