Skip to content

Commit

Permalink
Don't remember functions
Browse files Browse the repository at this point in the history
  • Loading branch information
pavi2410 committed Feb 20, 2022
1 parent 68288b4 commit 451cf8b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions hooks/src/main/java/me/pavi2410/useCompose/hooks/hooks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import androidx.compose.runtime.*
@Composable
fun useToggle(initialState: Boolean = false): Pair<Boolean, () -> Unit> {
var state by remember { mutableStateOf(initialState) }
val toggle = remember { { state = !state } }
return Pair(state, toggle)

fun toggle() {
state = !state
}

return Pair(state, ::toggle)
}

0 comments on commit 451cf8b

Please # to comment.