Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update <Await> to accept ReactNode as result #9896

Merged
merged 1 commit into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/light-pandas-confess.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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