Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

how to use sweetalert #1010

Discussion options

i read this web http://reactpy.dev/docs/guides/escape-hatches/javascript-components.html#dynamically-loaded-components . but what about for other js libraries like sweetalert . and i also want to use pdf js library later . but my code sweetalert is not working

from fastapi import FastAPI
from reactpy.backend.fastapi import configure
from reactpy import html,component,web
mui = web.module_from_template(
 # "react@^17.0.0",
 "react",
 # "@material-ui/core@4.12.4",
 # "sweetalert2",
 "@mui/material",
 fallback="waiting for my component .....",
)
ll = web.module_from_template(
 "react",
 "sweetalert2",
 fallback="waiting for my alert .....",
)
Alert = web.export(ll,"Swal")
Button = web.export(mui, "Button")
@component
def ViewButtonEvents():
 def showalert(event):
 Alert.fire({
 'title': 'Error!',
 'text': 'Do you want to continue',
 'icon': 'error',
 'confirmButtonText': 'Cool'
 })
 return html.div(
 Button(
 {
 "color": "primary",
 "variant": "contained",
 "onClick": showalert,
 },
 "Click Me!",
 ),
 )
app = FastAPI()
configure(app,ViewButtonEvents)
You must be logged in to vote

module_from_template is scheduled for removal due to random technical bugs. Your issue is likely related.

See #965 for more details

Replies: 3 comments 2 replies

Comment options

I have installed all packages with npm in my project. for material ui it works but sweetalert doesn't

You must be logged in to vote
0 replies
Comment options

@bobwatcherx could it be because showalert(event) accepts an event but one isn't passed for the Button's onClick: showalert?

You must be logged in to vote
2 replies
Comment options

That's definitely possible. My guess is that there's something else going wrong here. module_from_template, unfortunately is pretty finicky, so my guess is that's the issue.

Comment options

module_from_template is scheduled for removal due to random technical bugs. Your issue is likely related.

See #965 for more details

Answer selected by Archmonger
Comment options

Are there any logs in your browser's dev console or your terminal?

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /