Question : How can I use the result of a promise from JS to Mint (in the context of Webview) ? #535
-
In the snippet hereunder, a function f() (defined in Webview) is called via javaScript (using the "back-ticks" method). It works, but I was wondering how to pass the value returned by f() into a variable in the context of Mint. More precisely, I wanted to pass the value : value["m"] into the variable a hereunder:
|
Beta Was this translation helpful? Give feedback.
Answered by
gdotdesign
Feb 17, 2022
Replies: 1 comment 1 reply
-
Hi 👋 Couple of things to make this work:
So this in theory should work: component Main {
state val : String = "initial state"
fun modify() : Promise(Never, Void){
sequence {
value =
`f().then(value => value["m"])`
next { val = value }
}
}
fun render : Html {
<div>
<button onClick={modify}>
"Click Me!"
</button>
<text>
<{val}>
</text>
</div>
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
serge-hulne
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi 👋
Couple of things to make this work:
sequence
instead oftry
- this will make it asynchronous, and it will unwrapPromise(error, value)
So this in theory should work: