DEV Community

Discussion on: How To Write a Search Component with Suggestions in React

Collapse
 
saaage profile image
Stefan Age • Edited

There are a few ways you could hide the Suggestions component. I think a simple solution would be to create a state attribute called showSuggestions. Then you could show/hide it using React's short circuit syntax. In the render method add { this.state.showSuggestions && <Suggestions results={this.state.results} /> }. Then just use setState whenever you want to change the value of showSuggestions, for example when the user leaves the input field.

Collapse
 
naveensomanna profile image
naveensomanna

sir i am really confusing about setState Assynchronous function (its keep on calling Api even if setState is not change )

Collapse
 
naveensomanna profile image
naveensomanna

i hide the results but if i tried again in its shows no results

Collapse
 
naveensomanna profile image
naveensomanna

thank you sir