Last active
July 30, 2020 02:17
-
-
Save ShikaSD/dd0760ddbd8e4698301a408111cb5d3b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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