Open this example in the interactive library
Live preview
Source code
// components/DismissibleAnnouncement.tsx
import { useState } from "react";
import type { ReactNode } from "react";
export default function DismissibleAnnouncement({
title = "Delivery",
children = "Arrives in two days.",
}: { title?: string; children?: ReactNode } = {}) {
const [visible, set] = useState(true);
return visible ? (
<aside>
<strong>{title}</strong>
{children}
<button aria-label="Dismiss announcement" onClick={() => set(false)}>
×
</button>
</aside>
) : null;
}
