Skip to content

How to wrap a Client only Component? #453

Answered by dai-shi
aheissenberger asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, are you talking about SSR? (= is it only the case with --with-ssr?)

This is often an escape hatch.

export const ClientOnly = ({ children }: ClientOnlyProps) => {
const [hasMounted, setHasMounted] = useState(false);
useEffect(() => {
setHasMounted(true);
}, []);
if (!hasMounted) {
return null;
}
return children;
};

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by aheissenberger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants