Skip to content

[Question] JSX.Element vs React.ReactNode once again #129

Closed
@ivan-kleshnin

Description

@ivan-kleshnin

Hi. The Basic README claims that React.ReactNode is preferable to JSX.Element as a return value of a component because JSX.Element is a return type of React.createElement which is not, to put it simple, wide enough. Hovewer, when I attempt to use both to define the return type of a component, JSX.Element fits and React.ReactNode does not:

let C1 = (): JSX.Element => <div>test</div>
let c1 = <C1 />; // fine

let C2 = (): React.ReactNode => <div>test</div>
let c2 = <C2 />; // JSX Element type ReactNode is not a constructor function for JSX elements
// Type undefined is not assignable to type Element | null

What am I doing wrong?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy