How fix remember in Jetpack Compose?

The picture shows the code and logs For some reason startDate and endDate not recreated

enter image description here

1 answer

  • answered 2022-05-06 19:28 Nikola Despotoski

    Why do you want to remember the input dates? You already have them in the composable param input.

    You are getting different output because value in input has changed and has triggered recomposition, while in startDate and endDate you already have rememebered state from previous recomposition. On the next recomposition, the remember block won't be called, because the result already exists in the cache of the composer.

    Here is what you need to improve in this code:

    1. Remember the formatter, it's being recreated each recomposition.
    2. Don't remember the starDate and endDate from input object
    3. Format the dates only once, and remember that result instead, in case something else triggeres the recomposition.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum