Grunfeld provides two main usage patterns: simple alerts and dialogs that receive user responses. Each pattern is implemented using different overloads.
Confirmation dialogs that wait for user selection receive the removeWith function as a parameter. Call this function to close the dialog and return a result value.
import { grunfeld } from "@ilokesto/grunfeld";
function MyComponent() {
const showConfirm = async () => {
const result = await grunfeld.add<boolean>((removeWith) => ({
element: (
<div>
<p>Are you sure you want to delete this?</p>
<button onClick={() => removeWith(true)}>Confirm</button>
<button onClick={() => removeWith(false)}>Cancel</button>
</div>
),
}));
if (result) {
console.log("User clicked confirm");
} else {
console.log("User clicked cancel");
}
};
return <button onClick={showConfirm}>Confirmation Dialog</button>;
}