Skip to content

Instantly share code, notes, and snippets.

@ShikaSD
Last active July 30, 2020 02:17
Show Gist options
  • Save ShikaSD/dd0760ddbd8e4698301a408111cb5d3b to your computer and use it in GitHub Desktop.
Save ShikaSD/dd0760ddbd8e4698301a408111cb5d3b to your computer and use it in GitHub Desktop.
@Composable
fun Component(hasDiv: Boolean) {
// Note that Component does not add anything to tree directly
// Only calls to emit change "virtual DOM"
// Here it is called from div -> tag -> emit
if (hasDiv) {
div() // <-- adding or removing node here based on parameter, updating tree
}
}
@Composable
fun Test() {
// Changing this state results in re-execution of places it used in
var hasDiv by state { false }
// For example, state can be changed based on event from user (click)
button(onClick = { hasDiv = !hasDiv })
// This function will be re-invoked whenever hasDiv changes value
Component(hasDiv)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment