Jetpack Compose Remember inside LazyColumn

How to maintain remember (inside) Lazy Column, and not being destroyed after scroll back.

Well,, why I created story about Android? because this is who I am! Android and ML Engineer.


I will explain a little bit about remember. i hope this will help you.

Simple, if you have a state is in internal to a composable, then you can use remember.

In this example 1 is the value of the state that you want to maintain, the state can change it to 2 or another number in the future.

simply you can create inside compose function

and if you want to outside compose function, in this case outside Column()

Both of them works well and easy to maintain.

Remember inside Lazy column

But what if you want to use remember within the item inside lazy column?

actually you can simply just create inside LazyColumn,

but.. remember inside lazy column will destroy and re-initiate when you scroll away from the item (until you can’t see the item) and scroll back to the item (see again).

Then,, how to remember the remember even you scroll awaayyy? :P

you must initiate the remember outside LazyColumn.


or you can use rememberSaveable

what is this?

While remember helps you retain state across recompositions, the state is not retained across configuration changes. For this, you must use rememberSaveable. rememberSaveable automatically saves any value that can be saved in a Bundle.

not only retained across configuration or rotation changes but also retained from scroll away from the item.



Still believe, can change the world with code..

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store