Skip to content

Instantly share code, notes, and snippets.

@JacobWeisenburger
Created November 24, 2024 22:08
Show Gist options
  • Save JacobWeisenburger/dfb82949f99326f7fa5dce9115d52037 to your computer and use it in GitHub Desktop.
Save JacobWeisenburger/dfb82949f99326f7fa5dce9115d52037 to your computer and use it in GitHub Desktop.
Only render children on client
'use client'
import { useEffect, useState } from 'react'
// https://www.youtube.com/watch?v=KAjemAivU24
export function NoSSR ( { children }: { children?: React.ReactNode } ) {
const [ isClient, setIsClient ] = useState( false )
useEffect( () => { setIsClient( true ) }, [] )
return isClient ? <>{children}</> : null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment