https://kotlinlang.org logo
#react
Title
# react
f

Florent Martin

06/20/2022, 12:13 PM
Hi Community. I am very new to Kotlin JS and new to React Context. I am trying to use Context like in this example: https://codesandbox.io/s/zk58011yol . I want to have a button inside a component that can update the context of this component. Does someone knows if it is already possible to use useContext() like that and do you maybe have examples?
Copy code
var name by useContext(name1)
t

turansky

06/20/2022, 4:17 PM
Dirty example!!!
Copy code
val nameState = useState("My name!")

NameContext(nameState) {
    ... children
}
Usage:
Copy code
var name by useContext(NameContext)
But usually it has sense to use separate context for setter, because you will have new
nameState
(state array) every render
f

Florent Martin

06/20/2022, 5:10 PM
Thanks I’ll try to apply this
112 Views