prevent undefined values crash component
See original GitHub issueI’ve update the code manually, to prevent chrash the component with undefined values. My scenary is complex usign , redux, redux-form and sometimes the component is called when the values are not loaded , so they are undefined. Another select components prevent that.
I’d would be nice to add this code, I send where I had my updates where I hacked the code:
change 1:
var defaultShouldRenderSuggestions = function defaultShouldRenderSuggestions(value) {
if (typeof value === 'undefined') value = ''; // by me
return value.trim().length > 0;
};
chnage 2:
key: 'getQuery',
value: function getQuery() {
var inputProps = this.props.inputProps;
var value = inputProps.value;
var valueBeforeUpDown = this.state.valueBeforeUpDown;
if (valueBeforeUpDown === null && typeof value === 'undefined' ) { // by me
value= ' ';
valueBeforeUpDown ='';
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:6
Top Results From Across the Web
Node JS preventing value undefined crash - Stack Overflow
The problem is that the code crashes if there is no corresponding value for the user input value. If there is no corresponding...
Read more >How to Prevent the Error: Cannot Read Property '0' of Undefined
A guide on how to prevent the error "cannot Read Property '0' of Undefined", covering techniques such as try, catch, using const over...
Read more >7 Tips to Handle undefined in JavaScript - Dmitri Pavlutin
A detailed article about 'undefined' keyword in JavaScript. 7 tips on how to handle correctly 'undefined' and increase code durability.
Read more >Handling null and undefined in JavaScript | by Eric Elliott
In your own functions, you can avoid creating null or undefined values to begin with. There are a couple ways to do that...
Read more >Prevent Error with Default {} when Destructuring
When you use destructuring, make sure to set a default value of empty `{}` to prevent it from throwing an error...
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
Also came across this problem using React. Another workaround without touching the library code is to ensure the value: state is never undefined. If using inputProps from the example the value assignment can do a undefined check. From Basic Usage:
If the React tries to render without value state it will be populated with a safe empty string.
I have the same issue. At least check for the
typeof
string before using thetrim
function