Joost Klitsie
07/08/2020, 11:44 AMfun main(args: Array<String>) {
render(document.getElementById("root")) {
child(App)
}
}
val SomeContext = createContext(1)
val App = functionalComponent<RProps> {
SomeContext.Provider(5) {
typographyH1 {
+useContext(SomeContext).toString() // Actually shows '1'
}
}
}
Joost Klitsie
07/08/2020, 11:57 AMSomeContext.Consumer { value ->
Then the value is indeed '5' but I do not wish to use this, as it will complain that whatever I cannot use hooks within the Consumer { block
} as it is no longer a functionalComponentaraqnid
07/08/2020, 12:44 PMaraqnid
07/08/2020, 12:44 PMaraqnid
07/08/2020, 12:45 PMaraqnid
07/08/2020, 12:45 PMaraqnid
07/08/2020, 12:50 PMJoost Klitsie
07/08/2020, 12:54 PMfun main(args: Array<String>) {
render(document.getElementById("root")) {
child(App)
}
}
val SomeContext = createContext(0)
val OtherComponent= functionalComponent<RProps> {
val number = useContext(SomeContext).toString()
typographyH1 {
+number
}
}
val App = functionalComponent<RProps> {
val (newValue, _) = useState { 15 }
SomeContext.Provider(newValue) {
child(OtherComponent)
}
}
Joost Klitsie
07/08/2020, 1:03 PMJoost Klitsie
07/08/2020, 1:21 PMJoost Klitsie
07/08/2020, 1:25 PMaraqnid
07/08/2020, 1:37 PM