Hi ! I need a way to launch a simple check at each...
# compose
l
Hi ! I need a way to launch a simple check at each recomposition of my
@Composable
. So I'm using
SideEffect
, but it is not run at each screen update : so is there a better way ?
Copy code
@Composable
fun MyComposable() {
   SideEffect { checkDraw()}
   MySubComposable()
}
a
What are you trying to do and why?
l
It's a kind of complex operation : • I have the main logic in the ViewModel attached to the page of this composable -> it will cause the composable to recompose. • I need to launch a notification if checkDraw() succeed in the Composable, each time it is recomposed : checkDraw will launch the notification which could not be launched from the logic in the ViewModel, if necessary. Hence the SideEffect
It appears in fact that
SideEffect
is always run, but it is a problem in my
MutableStateFlow
. First, it returns the correct state, then an incorrect state is following. What I thought was a problem with
SideEffect
is in fact a problem with my
StateFlow
.
c
Having a side-effect run every time there is a recomposition sounds really inefficient. Can you model this by just reacting to some state change?
l
Yes, indeed, some days ago (I was not at home), I managed to implement my feature without needing
SideEffect
. I mean, I had to think again about the state I'm creating in my
@Composable
.
c
nice. yeah the new arch docs (updated a few days ago) really help push you in that right mindset about state. def recomend reading it if you haven't already
l
Yes thank you. I've read the documentation and created Repository, UseCase and ViewModel in order to handle the complexity of my application 😃