#Why use `useEffect` to avoid hydration error?

4 messages · Page 1 of 1 (latest)

oak bobcatBOT
#

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

deep orbit
#

If I apply logic to conclude that the following code is correct, Next throws hydr error at me

const [cards, setCards] = useState<TMemoGame['cards']>(prepareCards(props.cards))
#

I hate it because I am having an aesthetic issue as cards do not instantly appear on the page, only is the js loaded they will also appear. It makes layout shift

#

I seem to understand what's going on. The mismatch between server and client lists occurs because this function runs twice - once by server, once by client - and as prepareCards shuffles the list, the results differ