# android

Priyatanu Dey

11/08/2023, 5:18 PM
Hi I have a question, " "@Composable fun LazyColumn( ... state: LazyListState = rememberLazyListState(), ) instead of rememberX, why not have fun LazyColumn( state: T, onstateChange:(T) -> Unit) instead ?. whats the design decision?


11/08/2023, 5:27 PM
Do you have a custom built lazy column? if so, create the state wrapper and do the hoisting. if not, you can create a val for the rememberX and pass it to the lazy column, in addition, if you handle in your ui some composables that react with scrolling, for example, you can pass that lazy list state. Hope i answered parts of your question 🙂

Zach Klippenstein (he/him) [MOD]

11/08/2023, 8:19 PM
There’s probably a few reasons: First of all, LazListState is a service object, in a sense: you can call various scrollTo methods at any time. If it were a value object where you got a different instance each time, it would be more awkward to do that. Also it would require recomposing on every single frame during a scroll to update the scroll offset and layout info, which would kill performance. Additionally, I believe another reason is similar to why we ended up moving to this shape for text fields: there’s complex internal state that need to be changed and read at different times, eg between phases, within the same frame. If you just have a value and a callback, you can’t do that, because the calling code can only give you the updated state between frames.
👍 1

Priyatanu Dey

11/09/2023, 8:07 AM
Thank you so much 😊