Skip to content

Instantly share code, notes, and snippets.

@QVGK
Created May 30, 2023 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save QVGK/8d4b55d3f5b45b479fbeb92f20229c07 to your computer and use it in GitHub Desktop.
Save QVGK/8d4b55d3f5b45b479fbeb92f20229c07 to your computer and use it in GitHub Desktop.
Mounting Method SSR
import { useEffect, useState } from "react"
export default function Index(){
const [mounted, setMounted] = useState(false)
useEffect(() => {
setMounted(true)
})
if (!mounted) {
return null
}
return (
<div>
<h1>TESTING</h1>
</div>
)
}
@kooba
Copy link

kooba commented May 31, 2023

Yep this fixed my Nextjs Hydration failed because the initial UI does not match what was rendered on the server. issue... 👍

@QVGK
Copy link
Author

QVGK commented May 31, 2023

Yep this fixed my Nextjs Hydration failed because the initial UI does not match what was rendered on the server. issue... 👍

That's great to hear! SSR can really be a pain sometimes, but it really does have it's benefits sometimes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment