How to instert data from jetpack compose to mongo database? #62685
-
Select Topic AreaQuestion BodyI am trying to figure out how I can create 2 different textfields (name and phone-number) in jetpack compose that when the user enters this type of info and press the continue button, the information will asynchronously save until the person is navigated/enters the "mainscreen". After the user enters the "mainscreen" in this case just a screen with a column saying hello, will the information be saved in mongoDatabase. How can I achieve this? Appreciate the help and feedback! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Accessing and editing ViewModel variables from your views is a very bad practice. Here's another way to temporarily save values till the user goes to the next screen: Use the remember API to save the states of the TextFields between recompositions. At the Button's click, you then call the save function you have at the ViewModel. var name by rememberSaveable { mutableStateOf("") } OutlinedTextField( |
Beta Was this translation helpful? Give feedback.
Accessing and editing ViewModel variables from your views is a very bad practice. Here's another way to temporarily save values till the user goes to the next screen: Use the remember API to save the states of the TextFields between recompositions. At the Button's click, you then call the save function you have at the ViewModel.
var name by rememberSaveable { mutableStateOf("") }
var phoneNumber by rememberSaveable { mutableStateOf("") }
OutlinedTextField(
value = name,
onValueChange = { name = it },
...
)