# SaveBar Component The Save Bar API is used to indicate that a form on the current page has unsaved information. It can be used in 2 ways: 1. It is automatically configured when you provide the `data-save-bar` attribute to a [`form` element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form) and will display the save bar when there are unsaved changes. For more information, refer to the [save bar API](https://shopify.dev/docs/api/app-bridge-library/apis/save-bar). 2. It can be controlled declaratively through the `SaveBar` component. ```jsx import {SaveBar} from '@shopify/app-bridge-react'; export function MyApp() { const shopify = useAppBridge(); const handleSave = () => { console.log('Saving'); shopify.saveBar.hide('my-save-bar'); }; const handleDiscard = () => { console.log('Discarding'); shopify.saveBar.hide('my-save-bar'); }; return ( <> ); } ``` ## SaveBar component The `SaveBar` component is available for use in your app. It configures a save bar to display in the Shopify Admin. You can provide HTML ` ); } ``` Setting the disabled state of the Save and Discard buttons```jsx import {SaveBar} from '@shopify/app-bridge-react'; export function MyApp() { const shopify = useAppBridge(); return ( <> ); } ``` Set the `discardConfirmation` prop on the `SaveBar` component to show a confirmation modal after the user clicks the Discard button of the save bar```jsx import {SaveBar} from '@shopify/app-bridge-react'; export function MyApp() { const shopify = useAppBridge(); const handleDiscard = () => { shopify.saveBar.hide('my-save-bar'); }; return ( <> ); } ``` ### SaveBar controls Showing the save bar with the saveBar API```jsx import {SaveBar} from '@shopify/app-bridge-react'; export function MyApp() { const shopify = useAppBridge(); return ( <> ); } ``` Showing the save bar with the open prop```jsx import {useState} from 'react'; import {SaveBar} from '@shopify/app-bridge-react'; export function MyModal() { const [saveBarOpen, setSaveBarOpen] = useState(false); return ( <> ); } ``` ## Examples The Save Bar API is used to indicate that a form on the current page has unsaved information. It can be used in 2 ways: 1. It is automatically configured when you provide the `data-save-bar` attribute to a [`form` element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form) and will display the save bar when there are unsaved changes. For more information, refer to the [save bar API](https://shopify.dev/docs/api/app-bridge-library/apis/save-bar). 2. It can be controlled declaratively through the `SaveBar` component. ### SaveBar with different options Setting the loading state of the Save and Discard buttons```jsx import {SaveBar} from '@shopify/app-bridge-react'; export function MyApp() { const shopify = useAppBridge(); return ( <> ); } ``` Setting the disabled state of the Save and Discard buttons```jsx import {SaveBar} from '@shopify/app-bridge-react'; export function MyApp() { const shopify = useAppBridge(); return ( <> ); } ``` Set the `discardConfirmation` prop on the `SaveBar` component to show a confirmation modal after the user clicks the Discard button of the save bar```jsx import {SaveBar} from '@shopify/app-bridge-react'; export function MyApp() { const shopify = useAppBridge(); const handleDiscard = () => { shopify.saveBar.hide('my-save-bar'); }; return ( <> ); } ``` ### SaveBar controls Showing the save bar with the saveBar API```jsx import {SaveBar} from '@shopify/app-bridge-react'; export function MyApp() { const shopify = useAppBridge(); return ( <> ); } ``` Showing the save bar with the open prop```jsx import {useState} from 'react'; import {SaveBar} from '@shopify/app-bridge-react'; export function MyModal() { const [saveBarOpen, setSaveBarOpen] = useState(false); return ( <> ); } ```