Access a community of over 900,000 Shopify Merchants and Partners and engage in meaningful conversations with your peers.
Hello,
I'm integrating the Shopify Buy Button into my React app and noticed the Buy Button does not render unless the page is refreshed. In other words, the button does not appear when you're using React to navigate to pages that contain the Buy Button. Is there a way to programatically fire the script that loads the button when navigating through React routes?
To go into greater detail, the Buy Button does appear on the DOM when navigating through React routes. The iframe that is supposed to be generated by the Buy Button does not render, however. It only renders when the page is reloaded.
Any help would be greatly appreciated!
Hi Michael,
The Buy Button itself does not have an explicit method to render currently, it only loads at DOMContentLoaded.
However, if you'd like something more custom, the JS Buy SDK could be used for more explicit control over what you're rendering, which lends itself well to working in React. We're also working towards something that will wrap the SDK and provide UI components which could be more easily used, but it's not ready just yet.
Hope this helps!
Rich
Hi,
might be a little late but maybe it helps somebody.
What you have to do:
document.addEventListener('DOMContentLoaded', function (event) {
showProducts();
});
Hope that helps!
BR Marcel