Skip to content
Discussion options

You must be logged in to vote

Hi @Fred638, this suggestion to you.. So if I understand correctly, you want the "No data found" message to only appear after the button is clicked and the results come back empty, not before?

If that's the case, you probably need to track whether a search has been performed. Try adding a state like this:

const [hasSearched, setHasSearched] = useState(false);

const handleSubmit = async (e: React.FormEvent) => {
  e.preventDefault();
  setHasSearched(true);
  // ... your existing fetch logic
}

return (
  <div>
    {hasSearched && results.length === 0 ? (
      <div>No data found!</div>
    ) : (
      results.map(...)
    )}
  </div>
)

This way the "No data found" message only shows up a…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Fred638
Comment options

Answer selected by Fred638
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Ask and answer questions about GitHub features and usage Programming Help Discussions around programming languages, open source and software development
2 participants