Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing Context to Popup #192

Open
jo-goburdhun opened this issue Apr 28, 2022 · 0 comments
Open

Passing Context to Popup #192

jo-goburdhun opened this issue Apr 28, 2022 · 0 comments

Comments

@jo-goburdhun
Copy link

Please refer to this post.

I have a component which uses context and it works as expected when I include it in other components. But when I try to include that same component in a SweetAlert popup, I get the error:

Cannot destructure property 'cart' of '(0 , react__WEBPACK_IMPORTED_MODULE_0__.useContext)(...)' as it is undefined.

which means the component is not getting access to the context.

So when used outside of a SweetAlert popup, the component gets access to the context but not when inside the popup.

Here's my code for firing the popup:

const productModal = withReactContent(Swal);
function showProductPopupHandler(productId) {
        ProductService.get(productId).then((response) => {
            const product = response.data;

            return productModal.fire({
                html:
                    {/*other html*/}
                    <ShoppingCartQuantity productId={product.AMP_GUID} />
                ,
                showConfirmButton: false,
                showCloseButton: true
            });
        });
    }

If I remove the component from the popup, the popup works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant