How do I call Shopify App Bridge functions when using app bridge react?

Louise_Elmose_H
Shopify Partner
71 2 8

Hi,

I have an app with a frontend based on this example: https://shopify.dev/tutorials/build-a-shopify-app-with-node-and-react/build-your-user-interface-with... in order to use polaris. I do not directly use the App Bridge client in the app.

I now want to update the app to use the Shopify App Bridge, such that I can use session tokens, as required by january next year.

I am able to get an instance of the app bridge, but I am not able to call any of the functions on the app bridge instance - calling a function never resolves to the "then" promise clause, neither the "catch" clause.

I am using a local developer environment with ngrok, and the app is an embedded app.

 

A code example instantiating the app bridge and then trying to call a function on the app bridge:

const app = useAppBridge()
  console.log('app', app)
  app.getState().then((state) => console.log('state ', state)).catch((err) => console.log('err ', err))

Neither "state" or "err" is printed to the console.

What am I doing wrong?

 

Thanks,

-Louise  

0 Likes