Hey, I wanted to check out Kotlin 2.2.0-Beta1 and ...
# getting-started
h
Hey, I wanted to check out Kotlin 2.2.0-Beta1 and scout how I will be migrating from context-receivers to context-parameters. I know it's not released yet, but does someone know how I get the additional
with(this)
out here?
Copy code
/**
 * FC with Internationalization
 */

fun <P : Props> FCI(
    block: @ReactDsl context(IntlShape) ChildrenBuilder.(P) -> Unit,
) = FC<P> { props ->
    val intl = useIntl()
    block(intl, this, props)
}

val TestView = FCI<Props> { props ->
    with(this) {
        Grid { /* works */ }
    }
    Grid {
        /** 'fun <P : Props> ElementType<P>.invoke(noinline block: @JsoDsl() P.() -> Unit): Unit'
         * cannot be called in this context with an implicit receiver.
         * Use an explicit receiver if necessary.
         */
    }
}
The only other way I found would have been to have
IntlShape
as a value parameter so that it is always in the lambda parameters.
y
You need "Bridge methods" with context parameters, so you need to write a new
Grid
method that takes a context parameter, and delegates to the normal method
h
Hm, the
Grid
comes from Kotlin-Wrappers and there are hundres of others like it. I hope that the folks over there provide those Bridge methods 😞 Thank you for your help.
y
In a stable context parameters world, it'd be very likely that those bridge methods would be provided. In the meantime, it's worth it to write them yourself for experimentation
☝🏼 1