-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
createPortal return type is not a valid JSX element #925
Comments
just casting it maybe? i dont know TS enough to know if that's the way but the implementation is technically correct and works. |
Casting like so: return createPortal(<Object />, Scene) as JSX.Element fails with the same error. However, casting like so: return (createPortal(<Object />, Scene) as unknown) as JSX.Element will pass. Although I don't think this is quite the correct way. Is there anyone on the team who's particularly skilled in TS? I can look some more today as well. |
I think for TS in general yes, but this goes into reconciler internals so im not sure if anyone really has had experience with that. the react projects (dom, art, native) are all plain js, so we can't even look there. alternatively we could look at konva and ink, maybe they have found proper types. |
|
maybe the r3f implementation is outdated, i copied it directly from a suggestion from dan. ts aside, it still works fine though - not sure what the problem could be. |
An update: It look's like it is a problem with |
If export function createPortal(
children: React.ReactNode,
containerInfo: any,
implementation?: any,
key: any = null
): React.ReactNode {
if (!containerInfo.__objects) containerInfo.__objects = []
return {
$$typeof: REACT_PORTAL_TYPE,
key: key == null ? null : '' + key,
children,
containerInfo,
implementation,
}
} @stephencorwin do forbode any issues with this impl? |
Relevant code or config:
An example of using
createPortal
:The TS implimentation of
createPortal
from r3f library:What you did:
Tried to use
createPortal
in Drei'suseCamera.stories.tsx
as part of pmndrs/drei#223What happened:
The following TS error was thrown:
Problem description:
createPortal
should return a valid JSX element since it needs to be returned in the react component.Suggested solution:
I'm not sure yet, it probably needs someone who has more knowledge of r3f than I. I'll update if I have one.
The text was updated successfully, but these errors were encountered: