Colton Idle

    Colton Idle

    1 year ago
    Feel like I'm missing something basic. Anyone know why this doesn't compile?
    var myCount by remember { mutableStateOf(0) }
    val shouldDisplay = remember { derivedStateOf { (myCount > 1) } }
    Mitchell Skaggs

    Mitchell Skaggs

    1 year ago
    Make sure you have all the imports. There are a lot of extension functions required for the functionality. Intellij can help add imports automatically.
    Tash

    Tash

    1 year ago
    Seems to work… what error are you getting?
    Yea, make sure to have these imports:
    import androidx.compose.runtime.derivedStateOf
    import androidx.compose.runtime.mutableStateOf
    import androidx.compose.runtime.remember
    import androidx.compose.runtime.getValue
    import androidx.compose.runtime.setValue
    Colton Idle

    Colton Idle

    1 year ago
    All of my following composable fail after I add that line. Let me check the imports.
    Tash

    Tash

    1 year ago
    Seems to work ok…yea might be something to do with your env/file?
    Colton Idle

    Colton Idle

    1 year ago
    If I comment out that line then it works again.
    Tash

    Tash

    1 year ago
    What does the error say on AS ? (when you hover over
    OutlineTextField
    )
    Colton Idle

    Colton Idle

    1 year ago
    Restarting android studio did the trick. 😭
    Thank you everyone for checking my sanity.
    hfhbd

    hfhbd

    1 year ago
    Stupid question, is this approach preferred over a function/custom getter?
    Tash

    Tash

    1 year ago
    Do you mean regarding usage of
    derivedStateOf
    ?
    hfhbd

    hfhbd

    1 year ago
    yes
    Mitchell Skaggs

    Mitchell Skaggs

    1 year ago
    Yes,
    derivedStateOf
    allows the Compose runtime to understand dependent functions and only recompute values if necessary.
    hfhbd

    hfhbd

    1 year ago
    Good to know