Hello everyone, I am guessing there's something to...
# compose
n
Hello everyone, I am guessing there's something to the way remember works but I cannot make this work. My use case, load the profile from the backend and display it on the screen. Now when I first initialize the model for my composable I use dummy default values. Afterward, the backend fetches the profile and I want to render the new values. But it seems that even tho the composable gets recomposed, the remember values don't get updated (I guess that should happen lol). How can I go about this?
Copy code
val model by component.models.subscribeAsState()

val profile = model.profile

val about = remember { mutableStateOf(TextFieldValue(profile.about)) }
val email = remember { mutableStateOf(TextFieldValue(profile.email)) }
Firstly the values for about and email are "" empty string but later on they get updated and the state updates. Is there a way to achieve this behaviour? As I need this values later on for values in my textfields
Copy code
TextField(
            value = email.value,
            onValueChange = { email.value = it },
            label = { Text("Email") },
            readOnly = !isEditing
        )
l
In your situation, your source of truth is the model. So your updates need to be done on the model, not on the mutable states. Something like
onValueChange = { component.updateEmail(it) }
on your text fields
you don’t need the intermediate state, you can just use the component.models
n
@Luis true, thank you!
👍 1