State Management in Jetpack Compose Best Practices - Android Studio Tutorial

  Рет қаралды 2,244

K Apps

K Apps

Күн бұрын

State Management in Jetpack Compose is one of the most important things in order to create clean Composables, to separate responsibilities and to always display the right state to the user. In this video we will have a look at the best practices to manage your state. E.g. how to create state, where to create it or when you actually should use ViewModels / state holder classes.
00:00 How to properly create state variables
10:20 State holder classes (When to use ViewModels/plain state holders)

Пікірлер: 10
@marekwalica4418
@marekwalica4418 11 ай бұрын
very clear explanation
@goooozy
@goooozy Жыл бұрын
thanks bro it is very useful video
@ubersticks
@ubersticks Жыл бұрын
You do an excellent job on these tutorials. Maybe it is just a naming issue, but putting functions like showSnackbar() into a class called "ExampleState" seems like it is not a pure state now, but rather a utility class of sorts. I see what you are trying to do though and I like it - there are visible ui changes due to business logic changes that are reflected in the ViewModel state, and there are other ui changes that are purely ui logistics (like the scaffold state, scroll state, etc.) that you are putting into the ExampleState.
@kapps7407
@kapps7407 Жыл бұрын
I agree with you the naming could be better here. As from the Googles documentation a state holder (ExampleState in this video) can be seen as a class that extracts logic out of our composables. That includes UI Logic and UI State. With this approach we can make our composables only responsible for emitting UI (drawing, composition and so on) and I think this is a very neat approach in terms of separation of concerns. Triggering the snackbarhoststate.showSnackbar is UI Logic and thus can be put inside a state holder class. But maybe I haven't highlighted enough that such a plain state holder class does not only contain UI State but can also be responsible for UI logic.
@jopadjr
@jopadjr Жыл бұрын
7th...Thanks
@tmjromao
@tmjromao Жыл бұрын
Excellent! Could you elaborate ViewModel, share tips about how to set it up correctly, handle state, UI events? Many thanks, best regards
@kapps7407
@kapps7407 Жыл бұрын
Yes of course I can cover this in the next weeks 👍
@hashemmousavi2451
@hashemmousavi2451 Жыл бұрын
You deserve to have 100k followers not 100
@SimonSchubert
@SimonSchubert Жыл бұрын
I could be wrong but list.toMutableList().add(0,"C") at 8:50 should not modify the original list anyway.
@kapps7407
@kapps7407 Жыл бұрын
Oh yeah true but it does not change the problem , you can try it with mutableList when .add actually inserts the element.
Should You Use Compose State or StateFlow in Your ViewModels?
13:59
Philipp Lackner
Рет қаралды 74 М.
I'm Excited To see If Kelly Can Meet This Challenge!
00:16
Mini Katana
Рет қаралды 29 МЛН
Clown takes blame for missing candy 🍬🤣 #shorts
00:49
Yoeslan
Рет қаралды 48 МЛН
路飞太过分了,自己游泳。#海贼王#路飞
00:28
路飞与唐舞桐
Рет қаралды 38 МЛН
State in Jetpack Compose - remember & mutableStateOf
19:07
Konstantinos Reppas
Рет қаралды 2 М.
How to structure a JS/TS monorepo (From Zero to Turbo - Part 1)
11:58
State Hoisting with Jetpack Compose
10:29
CodingWithMitch
Рет қаралды 12 М.
Best practices for saving UI state on Android
20:36
Android Developers
Рет қаралды 38 М.
Collecting flows in a lifecycle-aware manner
6:35
Android Developers
Рет қаралды 17 М.
I'm Excited To see If Kelly Can Meet This Challenge!
00:16
Mini Katana
Рет қаралды 29 МЛН