Skip to content

Commit

Permalink
fix(toast): 🐛 useToast is not a function
Browse files Browse the repository at this point in the history
  • Loading branch information
navin-moorthy committed Nov 16, 2020
1 parent d7766f8 commit 2b35a42
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/toast/ToastProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from "react";
import ReactDOM from "react-dom";
import { canUseDOM } from "reakit-utils";
import { objectKeys } from "@chakra-ui/utils";

import { isFunction } from "../utils";
import { ToastController } from "./ToastController";
import { isFunction, createContext } from "../utils";
import { IToast, useToastState, ToastStateReturn } from "./ToastState";
import { objectKeys } from "@chakra-ui/utils";

const DEFAULT_TIMEOUT = 5000;
const PLACEMENTS = {
Expand All @@ -24,12 +24,26 @@ interface IToastContext extends ToastStateReturn {
toastTypes: ToastTypes;
}

export const [ToastContextProvider, useToast] = createContext<IToastContext>({
name: "useToast",
errorMessage:
"The `useToasts` hook must be called from a descendent of the `ToastProvider`.",
strict: true,
});
const ToastContext = React.createContext<IToastContext | undefined>(undefined);
export const ToastContextProvider = ToastContext.Provider;
export function useToast() {
const context = React.useContext(ToastContext);

if (!context) {
throw new Error(
"The `useToasts` hook must be called from a descendent of the `ToastProvider`.",
);
}

return context;
}

// export const [ToastContextProvider, useToast] = createContext<IToastContext>({
// name: "useToast",
// errorMessage:
// "",
// strict: true,
// });

export type ToastTypes = Record<
string,
Expand Down

0 comments on commit 2b35a42

Please sign in to comment.