useNotifications.tsx 773 B

1234567891011121314151617181920212223242526272829
  1. import React from "react";
  2. const NotificationsContext = React.createContext();
  3. // const defaultNotifications = () => [1, 2];
  4. export function NotificationsProvider(props) {
  5. const [notifications, setNotifications] = React.useState([]);
  6. // COMPONENTE SE MONTÓ
  7. React.useEffect(() => {}, []);
  8. const memData = React.useMemo(() => {
  9. // AQUI SE PONE TODO LO Q EL HOOK EXPORTA
  10. return { notifications, setNotifications };
  11. }, [notifications]);
  12. return <NotificationsContext.Provider value={memData} {...props} />;
  13. }
  14. export function useNotifications() {
  15. const context = React.useContext(NotificationsContext);
  16. if (!context) {
  17. // eslint-disable-next-line no-throw-literal
  18. throw "error: notifications context not defined.";
  19. }
  20. return context;
  21. }