Skip to content

Question : How can I use the result of a promise from JS to Mint (in the context of Webview) ? #535

Answered by gdotdesign
serge-hulne asked this question in Q&A
Discussion options

You must be logged in to vote

Hi 👋

Couple of things to make this work:

  • use sequence instead of try - this will make it asynchronous, and it will unwrap Promise(error, value)
  • just return the value in the promise and assign it to a variable

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>
  }
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@serge-hulne
Comment options

Answer selected by serge-hulne
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #534 on February 16, 2022 01:52.