Skip to content

v3.0.0 - Middleware support

Choose a tag to compare

@AlemTuzlak AlemTuzlak released this 05 Apr 12:30
· 33 commits to main since this release

Middleware mode

In order to be able to show toasts anywhere in the app you need to add the following code to your root.tsx file.

import { getToast, unstable_toastMiddleware } from "remix-toast/middleware";

export const loader = async ({ request }: LoaderFunctionArgs) => {
  // Extracts the toast from the request
  const toast = getToast(context); 
  // pass it to the client side
  return { toast }
}

export default function App({ children }: { children: ReactNode }) {
  const { toast } = useLoaderData<typeof loader>();
  
  useEffect(() => {
   if(toast){
    // Call your toast function here
    alert(toast.message);
   }
  }, [toast])

  return (
    ...
  );
}

// Export the middleware to be used in the app
export const unstable_middleware = [unstable_toastMiddleware()];

This change also should fix any sort of race condition issues that were reported in the past

What's Changed

New Contributors

Full Changelog: v2.0.0...v3.0.0