I have password and email fields, and a login button. Clicking the button should trigger the `viewMo...
m
I have password and email fields, and a login button. Clicking the button should trigger the
viewModel.login(email, pass)
function, but there’s a weird behavior where with every keystroke on the email or password field .. the ViewModel function get triggered. any idea how to solve that?
Copy code
var email = rememberSaveable { mutableStateOf("") }
        var password = rememberSaveable { mutableStateOf("") }

 Button(
            onClick = {
                viewModel.login(email.value, password.value)
            },
            enabled = uiState.value !is LoginResult.Loading,
            modifier = Modifier
                .fillMaxWidth()
                .padding(top = 16.dp)
        ) {
            Text("Login")
        }
c
Can we see the code for the fields?
m
It looks like that viewModel was created with each recomposition .. stupid me was passing it as a default param for the login screen.
c
How are you instantiating the view model?
m
As I said it was constructor initialization, that was the problem