单击其中的按钮时如何删除父 div?

How to delete the parent div when the button inside of it is clicked?

我有一个按钮,

<div
    key={index}
    className='flex items-center justify-between px-1 bg-accent-tm mr-2 mb-1 text-white-tm text-sm rounded-sm'
>
    <span className="pr-2">{tag}</span>
    <button>
        <XCircleIcon className="h-4" />
    </button>
</div>

看起来像这样,

我正在尝试删除 整个

元素

这是一个在点击时隐藏按钮的简单解决方案

export default function App() {
  const [hideButton, setHideButton] = useState(false);

  return (
    <div className="App">
      {hideButton ? null : (
        <div
          key={index}
          className="flex items-center justify-between px-1 bg-accent-tm mr-2 mb-1 text-white-tm text-sm rounded-sm"
          onClick={() => setHideButton(true)}
        >
          <span className="pr-2" onClick={(e) => e.stopPropagation()}>{tag}</span>
          <button>
            <XCircleIcon className="h-4" />
          </button>
        </div>
      )}
    </div>
  );
}