I’ve created an embedded react application using the new shopify-app-cli . I’m trying to dispatch a Redirect action but when I attempt to get the appbridge context it comes back undefined.
I’ve created another project by following the React, Node JS tutorial - and it contains the code below to get the context. This works perfectly within the tutorial project but when used in the CLI created project the appbridge context is undefined.
static contextTypes = {
polaris: PropTypes.object,
};
redirectToProduct = () => {
const redirect = Redirect.create(this.context.polaris.appBridge);
redirect.dispatch(
Redirect.Action.APP,
'/edit'
);
};
The _app file is different in the new CLI created application. It contains a Provider imported from @shopify/app-bridge-react which takes in a config object containing the API_KEY and shopOrigin. Is the appbridge context accessed through this Provider meaning it’s unnessesary to use createApp from shopify/app-bridge as in the code below taken from the Sopify Help Center?
import createApp from '@shopify/app-bridge';
import {Redirect} from '@shopify/app-bridge/actions';
const app = createApp({
apiKey: '12345',
shopOrigin: shopOrigin,
});
const redirect = Redirect.create(app);
Is there any documentation of @shopify/app-bridge-react that I can refer to as I’m sure I’m missing something obvious?
I’m also using the Loading and Titlebar components from @shopify/app-bridge-react which work great but I’m unsure how to dispatch an action or subscribe to an action when I can’t get the appbridge context. I can see via Redux Dev Tools that the START action is automatically dispatched when the Loading component is mounted but how can I manually dispatch the actions START and STOP? As I stated earlier, I can dispatch actions within the framework created within the tutorial project using this.context.polaris.appBridge as the app context but this doesn’t work in the CLI created project.





