Skip to content

[Bug]: Route component does not allow returning undefined from component #9620

Closed
@user72356

Description

@user72356

What version of React Router are you using?

6.4.3

Steps to Reproduce

export default function MyPage()
{
    return undefined;
}

const router = createBrowserRouter(createRoutesFromElements(
    <>
        <Route path="/" element={ <MyPage /> } />
    </>
));

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 returns undefined, only null.

Actual Behavior

Type 'undefined' is not assignable to type 'Element | null'.ts(2786)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions