-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
[Question] JSX.Element vs React.ReactNode once again #129
Comments
hmm @ferdaber is it viable to add @ivan-kleshnin - fine question. but for my purposes, i dont bother explicitly typing it. i just let TS infer it since its so easy to see: let C2 = () => <div>test</div>
let c2 = <C2 /> // c2: JSX.Element |
This specific case is not covered in the pitfalls section but is the same root cause as what is described in this section's "Minor Pitfalls" subsection: https://github.com/typescript-cheatsheets/react-typescript-cheatsheet#function-components. You can't return anything other than a JSX expression or |
ahh. gotcha. |
@ivan-kleshnin Could you quote the section that claims |
its the "how to type children" section https://github.com/typescript-cheatsheets/react-typescript-cheatsheet/blob/cc2ec67e0b36b7e838df8f2a54b4cd84df6c78cd/README.md#useful-react-prop-type-examples its specifically for typing children, which is correct. |
So, to underline, for class components I can use |
minor correction/caveat but yeah. |
Hi. The Basic README claims that
React.ReactNode
is preferable toJSX.Element
as a return value of a component becauseJSX.Element
is a return type ofReact.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 andReact.ReactNode
does not:What am I doing wrong?
The text was updated successfully, but these errors were encountered: