Skip to content

Commit

Permalink
chore:" remove typings from Deferred and useDeferredData
Browse files Browse the repository at this point in the history
To be added back in once we figur eout typing for useLoaderData in 6.5
  • Loading branch information
brophdawg11 committed Jul 18, 2022
1 parent 55ffecf commit 4d94cfb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
29 changes: 14 additions & 15 deletions packages/react-router/lib/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -429,34 +429,34 @@ function DataRoutes({
return useRoutes(routes || createRoutesFromChildren(children), location);
}

export interface DeferredResolveRenderFunction<Data> {
(data: Awaited<Data>): JSX.Element;
export interface DeferredResolveRenderFunction {
(data: Awaited<any>): JSX.Element;
}

export interface DeferredProps<Data>
extends Omit<React.SuspenseProps, "children"> {
children: React.ReactNode | DeferredResolveRenderFunction<Data>;
value: Data;
export interface DeferredProps {
children: React.ReactNode | DeferredResolveRenderFunction;
value: any;
fallback: React.SuspenseProps["fallback"];
errorElement?: React.ReactNode;
}

/**
* Component to use for rendering lazily loaded data from returning deferred()
* in a loader function
*/
export function Deferred<Data = any>({
export function Deferred({
children,
value,
fallback,
errorElement,
}: DeferredProps<Data>) {
}: DeferredProps) {
return (
<DeferredContext.Provider value={value}>
<React.Suspense fallback={fallback}>
<DeferredWrapper errorElement={errorElement}>
{typeof children === "function" ? (
<ResolveDeferred
children={children as DeferredResolveRenderFunction<Data>}
children={children as DeferredResolveRenderFunction}
/>
) : (
children
Expand Down Expand Up @@ -497,17 +497,16 @@ function DeferredWrapper({ children, errorElement }: DeferredWrapperProps) {
return <>{children}</>;
}

export interface ResolveDeferredProps<Data> {
children: DeferredResolveRenderFunction<Data>;
interface ResolveDeferredProps {
children: DeferredResolveRenderFunction;
}

/**
* @private
* Indirection to leverage useDeferredData for a render-prop API on <Deferred>
*/
export function ResolveDeferred<Data>({
children,
}: ResolveDeferredProps<Data>) {
return children(useDeferredData<Data>());
function ResolveDeferred({ children }: ResolveDeferredProps) {
return children(useDeferredData());
}

///////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions packages/react-router/lib/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -727,9 +727,9 @@ export function useRouteError() {
/**
* Returns the happy-path data from the nearest ancestor <Deferred /> value
*/
export function useDeferredData<Data>() {
export function useDeferredData() {
let value = React.useContext(DeferredContext);
return value as Awaited<Data>;
return value;
}

const alreadyWarned: Record<string, boolean> = {};
Expand Down

0 comments on commit 4d94cfb

Please sign in to comment.