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.

TypeError when using &&

See original GitHub issue

I wanted to remove a node depending on the value of model.isVisible.

TypeError: undefined is not an object (evaluating 'node.data')


Broken Code

export default ({isVisible}) =>
	{isVisible && <div>Example!</div>}

Workaround

export default ({isVisible}) =>
	{isVisible ? <div>Example!</div> : <div></div>}

Problem

In React the broken version should just work, I think it’s a cleaner solution (and actually it doesn’t create a DOM Node). I’m assuming this is a bug?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:16 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
jorgebucarancommented, Feb 20, 2017

@dodekeract Correct, null is not handled! I’ll add it soon 👍.

1reaction
FlorianWendelborncommented, Feb 16, 2017

@jbucaran Of course, the ternary operator is useful too. I use both all the time, depending on what exactly I want to achieve.

I still think the use-case for displaying a boolean is far more limited though. Especially since it isn’t even language-aware. It’ll display it in English all the time, which makes it useless for 75+% of the world. In addition to that I think returning false is probably the most explicit thing you can do to communicate “please don’t render this”.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError - JavaScript - MDN Web Docs
TypeError is a serializable object, so it can be cloned with structuredClone() or copied between Workers using postMessage() .
Read more >
TypeError when Using API in Javascript - Stack Overflow
The error means that question_data is undefined , therefore it doesn't have a question property, therefore it throws an error. Since you use ......
Read more >
How to Fix TypeError Exceptions in Python - Rollbar
The Python TypeError is an exception that occurs when the data type of an object in an operation is inappropriate. Learn how to...
Read more >
Handling TypeError Exception in Python - GeeksforGeeks
TypeError is raised whenever an operation is performed on an incorrect/unsupported object type. For example, using the + (addition) operator on ...
Read more >
Typeerror: int object is not callable – How to Fix in Python
In Python, a “Typeerror” occurs when you use different data types in an operation. For example, if you attempt to divide an integer...
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