1. Does it make sense to have a ‘key’ parameter fo...
# compose
t
1. Does it make sense to have a ‘key’ parameter for an
item
in LazyColumn/LazyRow? I know that it helps with
items
2. What’s the
key
composable for? I saw a code snippet recently where people were wrapping the content with
key
composable - inside an
items
block. Is there a difference between wrapping with
key
vs specifying the key in the items parameter itself. 3. Suppose that we’re sending a state object to a composable, but we’re not reading/getting the value. And now, if the state changes, would this cause a recomposition?
s
1. The
key
parameter is not mandatory. If the content of the lazylist doesn't change (i.e. you don't add, move or remove items), you actually don't need it. 3. No, if you don't read it, it won't cause a recomposition
t
1. The content of the lazy list does change. In my case, it has 6-8 dynamic
item
blocks and obviously an
items
block. In this case, would it be better to add a static key to the
item
block? 3. Understood!
h
For 3., if I understand correctly, you should not send a state to a composable directly, but instead use state hoisting. Furthermore, your Composable should not take / know parameters that it will not use.