Using createPortal in functionalComponent of Kotlin-react

Using createPortal in functionalComponent of Kotlin-react

Does anyone have some idea how to use createPortal in kotlin-react for example to render a modal? i have tried several ways and nothing is working. I´m new at Kotlin. Here is one way i tryed:

interface Modalprops:RProps{

var visible:Boolean

}

val modal = functionalComponent<Modalprops> {props->

val (container) = useState(document.create.div{+"asdasdsa"})

useEffectWithCleanup(emptyList()) {

document.body?.appendChild(container)

return@useEffectWithCleanup { document.body?.removeChild(container)}

}

createPortal(container){

if(props.visible) {

div { +"asdasd" }

}

}

}

fun RBuilder.OModal(isvisible:Boolean, handler:Modalprops.()->Unit) = child(modal){

attrs{

visible=isvisible

}

}

its just how its working in good old TS and i tried to transfer it to kotlin-react but createPortal seems to do nothing in this case.

It would be nice if some could give me an example of how implement this example correct in react-kotlin.

submitted by /u/Jimschi
[link] [comments]