Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

193
Views
how can you show a "no result found" after filtering?

how can you show a "no result found" after filtering?

const searchItems = (searchValue) => {
    setSearchInput(searchValue)
    if (searchInput !== '') {
        const filteredData = APIData.filter((post) => {
            return Object.values(post).join('').toLowerCase().includes(searchInput.toLowerCase())
        })
        setFilteredResults(filteredData)
    }
    else{
        setFilteredResults(APIData)
    }
}

I returned the filtered data but I didn't know how to return a "no result found" if the user types wrong data!

This is the text Input

<OutlinedInput 
                className="SearchInput"
                placeholder='Search...'
                onChange={(e) => searchItems(e.target.value)}
                endAdornment={
                    <InputAdornment>
                    <SearchIcon />
                    </InputAdornment>
                }
            />

I'm using

{searchInput.length > 0 ? () : ()}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You should check your filteredData after you recive the data.

if (searchInput !== '') {
    const filteredData = APIData.filter((post) => {
        return Object.values(post).join('').toLowerCase().includes(searchInput.toLowerCase())
    })
    if(filteredData){
        setFilteredResults(filteredData);
    }else{
       console.log("no result found");
    }
}
else{
    setFilteredResults(APIData)
}

Or check if your response contains some type you are looking for like

if (!isNumber(filteredData.id) && filteredData.id === 0) {
    console.log("no result found");
}

You can find some examples over here https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Array/filter

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!