TanStackT
TanStackβ€’12mo agoβ€’
18 replies
living-lavender

How do I show a toast from loader error?

Previously I used
useEffect
to make fetch data and if there was any error used catch to show a toast
 useEffect(() => {
const fetch = async () => {
    try {
     const blogs = await getDataFromApi();
       setBlogs(blogs);
     } catch (error) {
       showToast(error); πŸ‘ˆ shows toast
    }
 };
}, []);


But now I am able to console log the errro but I don't see any toast

  loader: async () => await getDataFromApi();

  onCatch(error, errorInfo) {
    console.log(`found error ${error}`);
    console.log(`found errorInfo ${errorInfo}`);

    showToast(error);
  },

  onError(error) {
    console.log(`found error ${error}`);
    showToast(error);
  },
Was this page helpful?