Site icon MageComp Blog

How to Implement App Bridge Toast API Instead of Deprecated Shopify Toast Component in Shopify Remix App?

In the world of e-commerce, Shopify stands tall as one of the most popular platforms for businesses to set up their online stores. With its versatile ecosystem and extensive set of tools, developers often find themselves immersed in the task of creating seamless user experiences within Shopify apps. However, as with any technology, updates and deprecations are inevitable, and staying up-to-date is crucial for maintaining the functionality and reliability of your app.

As technology evolves, so do the tools and APIs we use to build applications. If you’re a Shopify app developer using Remix, you may have encountered the deprecation of the Shopify Toast component. However, fret not! Shopify has provided an alternative solution in the form of the App Bridge Toast API.

Why Transition?

The Shopify Toast component was a convenient way to display notifications within your app. However, with the advancement of Shopify’s infrastructure and the introduction of App Bridge, it became necessary to migrate to more modern and supported methods. The App Bridge Toast API offers enhanced functionality and better integration with Shopify’s ecosystem, ensuring your app remains robust and future-proof. For developers working on Shopify Remix Apps, this transition presents an opportunity to enhance their apps with the latest features and ensure compatibility with future updates.

In this blog post, we’ll explore how to implement the App Bridge Toast API to replace the deprecated Shopify Toast component in your Shopify Remix App. But before that let’s find out the benefits of App Bridge Toast API and the difference between <Toast> and App Bridge Toast API.

Benefits of Using App Bridge Toast API:

Difference Between <Toast> and App Bridge Toast API:

In Shopify <Toast> is still working properly but it is deprecated in Shopify and it Uses more code space than App Bridge Toast API.

Steps to Implement App Bridge Toast API:

Step 1: Add Dependencies

Firstly you need to add dependencies in your remix code. Here we are creating app.test.jsx file for adding App Bridge Toast API.

Step 2: Install App Bridge

Now install Shopify App Bridge in your project. App Bridge serves as a bridge between your app and the Shopify admin, providing access to various APIs and UI components.

Step 3: Remove Deprecated Toast Component

Locate any instances where the deprecated Shopify Toast component is being used in your codebase and replace them with calls to the App Bridge Toast API.

Step 4: Add App Bridge Toast API

Here is the code given below to add App Bridge Toast API:

app.test.jsx 

import {
    Page,
    Button,
} from "@shopify/polaris";

export const loader = async () => {
    return null;
};

export default function Index() {
 const btnClick = (() => {
     shopify.toast.show("Button Clicked");
 });

 return (
   <Page>
       <Button variant="primary" onClick={btnClick}>
         Click for Toast
       </Button>
   </Page>
 );
}

Output:

Conclusion:

Transitioning from the deprecated Shopify Toast component to the App Bridge Toast API is a proactive step towards maintaining the quality and reliability of your Shopify Remix App. By following the steps outlined in this blog post and leveraging the capabilities of the App Bridge framework, you can seamlessly integrate toast notifications into your app while staying aligned with Shopify’s evolving ecosystem. Embrace the change, embrace the future of Shopify app development!

Exit mobile version