
main.react.useRefValue.kt Maven / Gradle / Ivy
@file:Suppress(
"NOTHING_TO_INLINE",
)
package react
import kotlin.reflect.KProperty
/**
* Only works inside [fc]
* @see Hooks and Function Components
*/
inline fun useRefValue(): RefValueInstance =
useRef()
.unsafeCast>()
/**
* Only works inside [fc]
* @see Hooks and Function Components
*/
inline fun useRefValue(
initialValue: T,
): RefValueInstance =
useRef(initialValue)
.unsafeCast>()
// TODO: make external in IR
class RefValueInstance
private constructor() {
inline operator fun getValue(
thisRef: Nothing?,
property: KProperty<*>,
): T {
return asDynamic().current
}
inline operator fun setValue(
thisRef: Nothing?,
property: KProperty<*>,
value: T,
) {
asDynamic().current = value
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy