I am trying to use the hook for App Bridge but it is blowing chunks because I don’t know. Please assist. So I load the useAppBridge. I then call it. I then try and use it. But the browser barks back at me this Uncaught Error. I was assuming the call to the hook useAppBridge, would return an App Bridge instance. Apparently, I was wrong. What is the deal here?
Uncaught Error: No AppBridge context provided. Your component must be wrapped in an AppBridge component.useAppBridge
useAppBridge.js:16
import { Provider, TitleBar, useAppBridge } from '@shopify/app-bridge-react';
import { getSessionToken } from '@shopify/app-bridge-utils';
const instance = axios.create();
export default instance;
function MyApp() {
const [status, setStatus] = useState();
const app = useAppBridge();
instance.interceptors.request.use(
function (config) {
return getSessionToken(app) // requires an App Bridge instance
.then((token) => {
config.headers['Authorization'] = `Bearer ${token}`;
console.log("Token from callback ", token);
return config;
});
}
);