Skip to content

Commit

Permalink
fix: update <Await> to accept ReactNode as result (#9896)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-ebey committed Jan 13, 2023
1 parent 7049c41 commit 44c03c6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/light-pandas-confess.md
@@ -0,0 +1,5 @@
---
"react-router": patch
---

update <Await> to accept ReactNode as children function return result
8 changes: 3 additions & 5 deletions packages/react-router/lib/components.tsx
Expand Up @@ -394,7 +394,7 @@ export function Routes({
}

export interface AwaitResolveRenderFunction {
(data: Awaited<any>): React.ReactElement;
(data: Awaited<any>): React.ReactNode;
}

export interface AwaitProps {
Expand Down Expand Up @@ -531,10 +531,8 @@ function ResolveAwait({
children: React.ReactNode | AwaitResolveRenderFunction;
}) {
let data = useAsyncValue();
if (typeof children === "function") {
return children(data);
}
return <>{children}</>;
let toRender = typeof children === "function" ? children(data) : children;
return <>{toRender}</>;
}

///////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 44c03c6

Please sign in to comment.