-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[Bug]: Route component does not allow returning undefined from component #9620
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
As far as I can tell, that type definition isn't coming from us anywhere. I tested and was able to use a component that returned |
@timdorr I hope you can see this reply. I think you were trigger-happy with the close button, not giving me a chance to reply and help you out.
export declare function Route(_props: RouteProps): React.ReactElement | null;
export declare type RouteProps = PathRouteProps | LayoutRouteProps | IndexRouteProps;
export interface PathRouteProps {
caseSensitive?: NonIndexRouteObject["caseSensitive"];
path?: NonIndexRouteObject["path"];
id?: NonIndexRouteObject["id"];
loader?: NonIndexRouteObject["loader"];
action?: NonIndexRouteObject["action"];
hasErrorBoundary?: NonIndexRouteObject["hasErrorBoundary"];
shouldRevalidate?: NonIndexRouteObject["shouldRevalidate"];
handle?: NonIndexRouteObject["handle"];
index?: false;
children?: React.ReactNode;
element?: React.ReactNode | null; <<<<<<<<<<<<<<<<<<< HERE
errorElement?: React.ReactNode | null;
} |
Yes, we accept a ReactNode or null, not Element or null. If you have React 18 compatible typedefs installed, this will work without error. Again, I confirmed as such with an example similar to yours. |
Everything is up to date. But I just found out it was a Typescript bug. DefinitelyTyped/DefinitelyTyped#18912 I'm curious how the repro example is working for you knowing about the above bug? Doesn't change anything in the end, just curious. |
What version of React Router are you using?
6.4.3
Steps to Reproduce
Expected Behavior
As of React 18, a component can return
undefined
instead of null. See official PR and write-up.At the moment, the TS typings for the
Route
component in react-router do not accept passing an element that returnsundefined
, only null.Actual Behavior
The text was updated successfully, but these errors were encountered: