Search suggestions popup not closing in react

I am trying to build an input box where the user will type inputs and based on the input there will be an suggestions popup under the input box where suggestions will be shown. In my code the suggestions are showing perfectly but when I give more inputs the previous popover doesn’t close.

return <div className="border border-gray-400 rounded-md mx-10 my-10 h-10 relative">
      <input
        value={value}
        onChange={(e) => setValue(e.target.value)}
        className="w-full border-none absolute inset-0 z-10 outline-none px-2 text-sm bg-transparent"
        style={{ WebkitTextFillColor: "transparent" }}
        maxLength={maxLength}
      />
      <div className="text-sm absolute inset-0 flex items-center px-2 whitespace-pre">
        {value.split(" ").map((word, i) => {
          const isHighlighted = word.toLowerCase().includes(suggestions[0]);
          return (
            <div className="relative" key={i}>
              {isHighlighted ? (
                <>{getHighlightedSyntex(word, i)}</>
              ) : (
                getSyntex(word, i)
              )}
              {getSuggestions(word)}
            </div>
          );
        })}
      </div>
    </div>

This is where I am showing my renders. That getSuggestions function is,

 const getSuggestions = (word) => {
    const matchedPartialSuggestions = suggestions.filter(
      (item) => word !== "" && item.toLowerCase().startsWith(word.toLowerCase())
    );
    console.log('va', word, matchedPartialSuggestions)
    return (
      <>
        {matchedPartialSuggestions.length > 0 && (
          <div className="absolute z-10 p-2 bg-white border rounded shadow-lg">
            {matchedPartialSuggestions?.map((item, i) => {
            return <p key={i}>{highlightMatching(word, item)}</p>;
            })}
          </div>
        )}
      </>
    );
  };

Here in the functions, I am showing that popup that contains search suggestions. I know why the popup doesn’t close it’s because when I type something that matches the data from suggestions, the variable from getSuggestions functions got the data as filtered value. That’s why the popup doesn’t close. But i need to the search suggestions only when any inputted value matches the search suggestions data, otherwise the popup will be always hidden.