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

PanelResizeHandle cannot be used as a JSX component (wrong types) #256

Closed
tomaszferens opened this issue Jan 5, 2024 · 4 comments · Fixed by #259
Closed

PanelResizeHandle cannot be used as a JSX component (wrong types) #256

tomaszferens opened this issue Jan 5, 2024 · 4 comments · Fixed by #259

Comments

@tomaszferens
Copy link

I'm getting an error for PanelResizeHandle when rendering an example from docs.

TS Error:

'PanelResizeHandle' cannot be used as a JSX component.
  Its return type 'ReactNode' is not a valid JSX element.
    Type 'string' is not assignable to type 'Element'.(2786)

Code:

import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';

import { PanelGroup, Panel, PanelResizeHandle } from 'react-resizable-panels';

export const App = () => {
  return (
    <div>
      <PanelGroup direction="horizontal">
        <Panel defaultSize={30} minSize={20}>
          left
        </Panel>
        <PanelResizeHandle />
        <Panel minSize={30}>middle</Panel>
        <PanelResizeHandle />
        <Panel defaultSize={30} minSize={20}>
          right
        </Panel>
      </PanelGroup>
    </div>
  );
};

const root = createRoot(document.getElementById('app'));

root.render(
  <StrictMode>
    <App />
  </StrictMode>
);

Stackblitz: https://stackblitz.com/edit/stackblitz-starters-zbzfr8?file=src%2Findex.tsx

Every package is up to date (latest):

image

@bvaughn
Copy link
Owner

bvaughn commented Jan 6, 2024

I think React TypeScript types have changed recently to better work with server components (vercel/next.js#42292) so the fix here is probably for me to update the return types this library declares. In the meanwhile, you can cast or ts-ignore this error.

@tomaszferens
Copy link
Author

I think React TypeScript types have changed recently to better work with server components (vercel/next.js#42292) so the fix here is probably for me to update the return types this library declares. In the meanwhile, you can cast or ts-ignore this error.

Yeah I went with @ts-expect-error for now 🙏

@QianKuang8
Copy link

I think React TypeScript types have changed recently to better work with server components (vercel/next.js#42292) so the fix here is probably for me to update the return types this library declares. In the meanwhile, you can cast or ts-ignore this error.

Thanks for the answer, it helps me to solve the error

bvaughn added a commit that referenced this issue Jan 9, 2024
…er than React Node) (#259)

This is being done to address recent TypeScript React changes that cause "cannot be used as a JSX component" errors.

Resolves #256
@bvaughn
Copy link
Owner

bvaughn commented Jan 9, 2024

This fix just went out with 1.0.8


❤️ → ☕ givebrian.coffee

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants