skip to Main Content

I’m trying to use react-hot-toast library in my project.
Following the Getting Started guide on their NPM site I’ve:

  • installed the library,
  • imported toast and Toaster,
  • added notify function,
  • added the div with button and Toaster.
import toast, { Toaster } from 'react-hot-toast';

const notify = () => toast('Here is your toast.');

const App = () => {
  return (
    <div>
      <button onClick={notify}>Make me a toast</button>
      <Toaster />
    </div>
  );
};

After running my app I get this error. Commenting out the Toaster makes the error go away, but then the toasts don’t work (obviously…).

I’ve tried:

  • explicitly specifying toastOptions -> same error,
  • moving the Toaster to other parts of app (index.jsx, app.jsx) -> same error,
  • using different library (react-toastify) -> same behaviour, but with useReducer error. Toastify also doesn’t show the error after commenting out ToastContainer (equivalent to Toaster).

I’m most concerned about the last point, which makes it pretty obvious, that the problem is something in my app structure. But this is my first project in react and I’m not sure how to approach resolving it.

One last additional info that could be relevant: I’ve installed several libraries to this project (fullcalendar, momentjs…). They all work fine. I’ve tried to install three new during last 7 days (react-hot-toast, react-toastify, i18n). None of them work because of useState/useReducer errors.

Thanks for any help or tips.

2

Answers


  1. Chosen as BEST ANSWER

    For anyone in my situation - if you have separate package.json files and node_modules folders for frontend and backend, don't spend the whole weekend trying to debug a well working code. Instead, check the current folder opened in terminal when installing the library.


  2. In this case, trying the package in a code sandbox is a good idea.

    Here I have set it up for you; as you can see, it works just fine.

    So the problem is not with the toast component.
    Do you have some more code or is this the whole project?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search