Initial commit
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
"use client";
|
||||
import { createContext, useCallback, useContext, useMemo, useState } from "react";
|
||||
|
||||
type Ctx = { open: boolean; toggle: () => void; close: () => void };
|
||||
const C = createContext<Ctx | null>(null);
|
||||
|
||||
export function TrashPanelProvider({ children }: { children: React.ReactNode }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const toggle = useCallback(() => setOpen((o) => !o), []);
|
||||
const close = useCallback(() => setOpen(false), []);
|
||||
const value = useMemo<Ctx>(() => ({ open, toggle, close }), [open, toggle, close]);
|
||||
return <C.Provider value={value}>{children}</C.Provider>;
|
||||
}
|
||||
|
||||
export function useTrashPanel() {
|
||||
const ctx = useContext(C);
|
||||
if (!ctx) throw new Error("useTrashPanel must be used within TrashPanelProvider");
|
||||
return ctx;
|
||||
}
|
||||
Reference in New Issue
Block a user