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.

Result section don't hide after click

See original GitHub issue

So, when I click one of the results, the ‘onPress’ is fired, but the result section don’t hide. This happens only if there is an ‘onPress’ function defined

For example, my onPress had this simple function: console.log(details.geometry.location). In this case, results were hidden after click, as expected.

Next time, my function got complicated and it had something like: this.handlePress(details.geometry.location). This time, results didn’t hide. I am quite sure handlePress is not causing any issue, it only has setState within it. That’s a very simple thing, right? Anything other than console.log keeps the result from hiding. I think it’s a bug

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:8

github_iconTop GitHub Comments

6reactions
danbockappscommented, Jul 23, 2019

@ibrahimsenan’s solution worked for me. Example code:

<GooglePlacesAutocomplete
...
listViewDisplayed={this.state.listViewDisplayed}
onPress={()=>this.setState({listViewDisplayed: false})}
/>

GooglePlacesAutocomplete automatically takes care of setting listViewDisplayed to true when the user is typing their search terms.

5reactions
i1990jaincommented, Jun 18, 2019

the shouldComponentUpdate function should return false for any set state done in the onPress function

shouldComponentUpdate(nextProps, nextState){

      if(this.state.locationData != nextState.locationData) {
          return false;
      }

      if(this.state.locationDetails != nextState.locationDetails) {
         return false;
      }

      if(this.state.address != nextState.address) {
        return false;
      }
      return true;
    }

the on press function

onPress={(data, details = null) => { 
                  this.setState({ locationDetails:details });
                  this.setState({ locationData:data });
                  this.setState({ address: data.description });

                }}
Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Hide search results when clicked anywhere expect ...
Hide search results when clicked anywhere expect on search results in Jquery ; type · "text" ; id · "MainPageSearchBar" ; placeholder ·...
Read more >
Show and hide sections using click or mouse over
How to show and hide sections using click or mouse over in HTML.
Read more >
Lesson 5: Using Javascript to Hide and Show Content
It's common practice on today's web to hide content from users until it's needed. In this lesson, you will hide your clock, then...
Read more >
Hide or display the Paste Options button - Microsoft Support
This article explains how to show or hide the Paste Options button on a PC. Click the File tab, then click Options. Note:...
Read more >
Hide poll results - Slido Community
If you click on the Hide live results checkbox while creating your polls, it will prevent the audience from seeing the results right...
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