https://kotlinlang.org logo
Title
c

Colton Idle

01/19/2022, 6:03 PM
Can you
remember {}
a when statement? I'm trying something like this
remember{
   when (someValue) {
       optionA -> {
           doSomething()
but I get an error of "remember calls must not return Unit"
d

Dominaezzz

01/19/2022, 6:04 PM
I think you want
DisposableEffect
.
Since you don't seem to `remember`ing anything.
c

Colton Idle

01/19/2022, 6:16 PM
Hm. Thanks for making me think harder here. I suppose you're right. And I suppose I need to read the sideEffects docs for like the 10th time. Something with sideeffects just doesn't click for me. 😭
This first line in the docs always gets me. "Composables should be side-effect free." I think I also picked up this habbit from @jim as I'm allergic to CompositionLocals and SideEffects in my code. Any time I see them I try to get rid of them. Could the first sentence in the docs be interpreted as "Composable should typically be free of side-effects, but they are necessary in some cases" ?
d

Dominaezzz

01/19/2022, 6:20 PM
Well, maybe it should say. Wrapping your side effects with
*Effect
removes the side effect from the composable.
Or rather, there should no side effects ran during composition.
j

jim

01/19/2022, 6:21 PM
I think that is covered by "should" (see: https://www.ietf.org/rfc/rfc2119.txt)
❤️ 1
🤣 1
💯 1
Btw, @Colton Idle, your allergy is probably a good thing. Your code will be much better than everyone else's as a result 😇
c

Colton Idle

01/19/2022, 6:23 PM
ooof. got hit with the rfc link. 😂 @jim appreciate it though. I guess like I said, Im just very "against" having these in my app so I typically try other things first. In this case... it looks like its necessarythough. @Dominaezzz thanks for your help. I went for LaunchedEffect and it did what I expected. 🙏