TypeError when using &&
See original GitHub issueI 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:
- Created 7 years ago
- Comments:16 (10 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@dodekeract Correct, null is not handled! I’ll add it soon 👍.
@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”.