#how to properly use useEffect?

11 messages · Page 1 of 1 (latest)

teal river
#

So right now i'm using appwrite with next js.
I don't know why it doesn't show up instantly. Am i doing something wrong? I know my code is not that organized but a few tips would be nice.

visual helmBOT
#

🔎 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)

teal river
#

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

silk sapphire
#

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.

umbral moat
# teal river This is for the sidebar, the "Controls" shows up late until the console prints "...

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()