-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
@types/react does not allow returning ReactPortal from render #20942
Comments
I wonder if this is related, I was just following the tutorial here: https://www.typescriptlang.org/docs/handbook/react-&-webpack.html And webpack gave me the error "Module has no exported member 'ReactPortal'". Do I need to use a specific version of react or @ types/react?
|
I got it working! First I noticed the version of So I ran Edit:
|
Thanks @charlieman, adding |
I am seeing this with
So I don't have anything down in 15.x. and have no idea why this is happening. I did |
Ok, so I seem to have figured something out. When I used As mentioned above, Here is a diff if it could be helpful of the working (new) vs failing yarn.lock: https://gist.github.com/rosskevin/9966b40017a82404147c96327543a40b |
just found out the topic was totally off. @Kovensky i met the same problem, i think the only solution is to update the type definition file. making |
interface ReactPortal extends ReactElement<any> {
key: Key | null;
children: ReactNode;
} this works for me. |
I'm still unable to fix this. The problem appears to be that @types/react-dom installs an older version of @types/react as you can see from the error trace:
Here's what I've got going in my package.json:
And here's what in my yarn.lock:
|
Lol, my resolution differed from the dependency version. Also note for others, you can pin version in subpackages (using resolutions)[https://yarnpkg.com/lang/en/docs/selective-version-resolutions/]
|
I'm trying to use a React.SFC and using a react portal inside complains saying it doesn't have a render function. Anyone know of a fix here? |
@lifeiscontent I ran into the same problem. Don't know how to fix it, but I managed to work around it by not using JSX. So instead of this:
you can use your component like this:
|
@lifeiscontent I 'fixed' it by wrapping a |
This seems to be fixed with @types/react-dom@16.8.0 |
At Its return type '{ $$typeof: number | symbol; key: string | null; children: any; containerInfo: any; implementation: any; }' is not a valid JSX element. I've noticed in function createPortal(children: React.ReactNode, containerInfo: any, implementation?: any, key: any = null) {
if (!containerInfo.__objects) containerInfo.__objects = []
return {
$$typeof: REACT_PORTAL_TYPE,
key: key == null ? null : '' + key,
children,
containerInfo,
implementation,
}
} Wrapping the call in a fragment does work, but it's not ideal because we have to ask the user to impliment that... |
Hi thread, we're moving DefinitelyTyped to use GitHub Discussions for conversations the To help with the transition, we're closing all issues which haven't had activity in the last 6 months, which includes this issue. If you think closing this issue is a mistake, please pop into the TypeScript Community Discord and mention the issue in the |
A
ReactPortal
is not accepted as a validReactElement
as it does not have atype
orprops
key. However, React itself does acceptReactPortals
as a valid return value.This might be a bit tricky to fix as simply changing
StatelessComponent
/ComponentClass
to returnReactElement|ReactPortal
will probably break many things.This problem will also probably repeat itself with future
React.Fragment
.The text was updated successfully, but these errors were encountered: