sickdyd / react-search-autocomplete

A search box that filters the provided array of objects
https://sickdyd.github.io/react-search-autocomplete
MIT License
218 stars 82 forks source link

How to show Message if related data not found #41

Closed Chinmaypattar closed 2 years ago

Chinmaypattar commented 2 years ago

How to show a error message like "No Data Found" ,when we didn't get the any value

sickdyd commented 2 years ago

@Chinmaypattar You can figure out if there are no ersults on handleOnSearch; check the demo code:

  const handleOnSearch = (string, results) => {
    console.log(string, results);
    // results contains the list of results, if its length is 0, it means that nothing was found
    if (results.length === 0) {
      alert("No results");
      // or add your custom code to show the error
    }
  };
Chinmaypattar commented 2 years ago

But I want to show the Message in the tray where Results will be shown

sickdyd commented 2 years ago

@Chinmaypattar This sounds like a new feature. I'll try to add it when I have the time.

sickdyd commented 2 years ago

@Chinmaypattar I added the option in version 7.0.0. It is enabled by default, so you can see it already in the demo version: https://sickdyd.github.io/react-search-autocomplete/

More info about the feature in the props section of the readme (the last entries).