Skip to content

Commit

Permalink
fix: make ssrFallback take callback as children
Browse files Browse the repository at this point in the history
  • Loading branch information
p-sw committed Jul 19, 2024
1 parent 13cc43d commit 9113b8e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/react/lib/ssrFallback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { type ReactNode, useEffect, useState } from "react";
* This component allows components to use `document` as like they're always in the client side.
* Return null if there is no `document` (which represents it's server side) or initial render(to avoid hydration error).
*/
function ServerSideDocumentFallback({ children }: { children: ReactNode }) {
function ServerSideDocumentFallback({
children,
}: { children: () => ReactNode }) {
const [initialRender, setInitialRender] = useState<boolean>(true);

useEffect(() => {
Expand All @@ -14,7 +16,7 @@ function ServerSideDocumentFallback({ children }: { children: ReactNode }) {
if (typeof document === "undefined" /* server side */ || initialRender)
return null;

return children;
return children();
}

export { ServerSideDocumentFallback };
2 changes: 1 addition & 1 deletion packages/react/lib/withSSD.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function withServerSideDocument<P extends {}>(
const SSDocumentFallbackWrapper = (props: P) => {
return (
<ServerSideDocumentFallback>
<Component {...props} />
{() => <Component {...props} />}
</ServerSideDocumentFallback>
);
};
Expand Down

0 comments on commit 9113b8e

Please sign in to comment.