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.

prevent undefined values crash component

See original GitHub issue

I’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:open
  • Created 6 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

8reactions
JAG0991commented, Jan 24, 2019

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:

...
// Autosuggest will pass through all these props to the input.
    const inputProps = {
      placeholder: 'Type a programming language',
      value: value ? value : '',
      onChange: this.onChange
    }; 
...

If the React tries to render without value state it will be populated with a safe empty string.

1reaction
alexcrooxcommented, Jan 7, 2018

I have the same issue. At least check for the typeof string before using the trim function

Read more comments on GitHub >

github_iconTop 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 >

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