Nikola Milovic
09/12/2021, 6:58 AMexternal interface RootProps : PropsWithChildren {
var component: Root
}
val RootC = fc<RootProps> { props ->
val (routerState, _) = useState(props.component.routerState.value)
val child: Root.Child = routerState.activeChild.instance
And I'd call this way in my toplevel app component
override fun RBuilder.render() {
RootC {
attrs {
this.component = root
}
}
}
But this doesn't seem to pickup on the state val (routerState, _) = useState(props.component.routerState.value)
and doesn't update the component. No composables, so cannot use the ValueExt from the samplesArkadii Ivanov
09/12/2021, 8:19 AMArkadii Ivanov
09/12/2021, 8:30 AMNikola Milovic
09/12/2021, 9:25 AMfun <T : Any> Value<T>.subscribeAsState(): T {
val (state, setState) = useState<T>(this.value)
useEffectOnce {
val observer: ValueObserver<T> = {
setState(it)
}
subscribe(observer)
cleanup {
unsubscribe(observer)
}
}
return state
}
And I just use it like this
val RootC = fc<RootProps> { props ->
val routerState = props.component.routerState.subscribeAsState()
val child: Root.Child = routerState.activeChild.instance
Are there any issues that stick out at first glance? I suck at thisArkadii Ivanov
09/12/2021, 10:24 AM