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

Deferred leads to type error when used as a React component #2207

Open
shosti opened this issue Jan 23, 2025 · 1 comment
Open

Deferred leads to type error when used as a React component #2207

shosti opened this issue Jan 23, 2025 · 1 comment
Labels
react Related to the react adapter

Comments

@shosti
Copy link

shosti commented Jan 23, 2025

Version:

  • @inertiajs/react version: 2.0.2
  • typescript: 5.4.5

Describe the problem:

When wrapping a component with Deferred like so:

export default function PageWrapper() {
  return (
    <Deferred data="props" fallback={<div>Loading ...</div>}>
      <Page />
    </Deferred>
  );
}

function Page() {
  return <div>Page</div>;
}

I get the following type error:

error TS2786: 'Deferred' cannot be used as a JSX component.
  Its return type 'string | number | ReactElement<unknown, string | JSXElementConstructor<any>>' is not a valid JSX element.
    Type 'string' is not assignable to type 'ReactElement<any, any>'.

Looking at the generated types, this error seems correct:

declare const Deferred: {
    ({ children, data, fallback }: DeferredProps): string | number | ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
    displayName: string;
};

We're using inertia-rails (the behavior seems correct, the types just look wrong).

@shosti shosti added the react Related to the react adapter label Jan 23, 2025
@Verox001
Copy link

Verox001 commented Jan 29, 2025

Could you please show how you imported Deferred? Also try updating to Version 2.0.3. Maybe that issue was already fixed @shosti

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
react Related to the react adapter
Projects
None yet
Development

No branches or pull requests

2 participants