@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
26 lines • 809 B
JavaScript
import React, { useState, useMemo, useContext } from "react";
const ToastContext = React.createContext({
dismissToast: () => { },
pushToast: () => { },
toasts: [],
});
export function useToasts() {
return useContext(ToastContext);
}
export function ToastProvider({ children }) {
const [toasts, setToasts] = useState([]);
const api = useMemo(() => ({
dismissToast: (id) => {
setToasts(currentToasts => currentToasts.filter(item => item.id !== id));
},
pushToast: (newToast) => {
setToasts(currentToasts => [...currentToasts, newToast]);
},
}), []);
const value = {
toasts,
...api,
};
return React.createElement(ToastContext.Provider, { value: value }, children);
}
//# sourceMappingURL=index.js.map