question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Return null as JSX element (no-null with React + TS)

See original GitHub issue

Is necessary return null for a JSX Element

Screen Shot 2020-12-26 at 8 31 25 PM

If use undefined TS return an error

Its return type 'Element | undefined' is not a valid JSX element.
Type 'undefined' is not assignable to type 'Element | null'.

Maybe enable null for a JSX return fix the bug.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
Torhalcommented, Jan 23, 2021

Or possibly return an empty React.Fragment. I do that instead of using null.

return isLoading
    ? <></> 
    : (
            /* ... */
       )
7reactions
sindresorhuscommented, Jan 12, 2021

We could maybe ignore reporting on null when in a JSX context or something.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to return an empty jsx element from the render function in ...
I think just add { null } not null , in your section to show empty component.
Read more >
Conditional Rendering - React
Use JavaScript operators like if or the conditional operator to create elements representing the current state, and let React update the UI to...
Read more >
Documentation - TypeScript 2.0
TypeScript has two special types, Null and Undefined, that have the values null and undefined ... return a + b; // Produces value...
Read more >
Optional chaining (?.) - JavaScript - MDN Web Docs - Mozilla
When used with function calls, it returns undefined if the given function ... For example, if obj.first is a Falsy value that's not...
Read more >
its return type 'element | The AI Search Engine You Control
sindresorhus/eslint-plugin-unicornReturn null as JSX element (no-null with React + TS)#964. Created almost 2 years ago. 7. Is necessary return null for a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found