JetBrains / kotlin-wrappers

Kotlin wrappers for popular JavaScript libraries
Apache License 2.0
1.34k stars 164 forks source link

How to cast a hook? Or how to get it's value in the right type? #2231

Closed edpichler closed 6 months ago

edpichler commented 6 months ago

I need to pass a Double as a parameter in a method, although, the origin is from a hook.

So I have: var total = useState(0.0)

How can I cast it as a Double? Or get the Double value?

I am having a hard time finding the syntax.

turansky commented 6 months ago

For now we support 2 syntaxes:

  1. Default

    var total by useState(0.0)
  2. With extended setter

    val (total, setTotal) = useState(0.0)

JFYI For such questions you can use official Kotlin Slack - in common case you will receive answer faster

edpichler commented 6 months ago

My bad! I was using = instead of by to declare my variable.