[TIL] ๐ผ24/05/03๐ผ#mutableStateOf vs mutableStateListOf
mutableStateOf vs mutableStateListOf
๐์ฐธ๊ณ ์๋ฃ
mutableStateOf<List<T>>
๋ immutable list ์ํ๋ฅผ ๊ด๋ฆฌํ ๋ ์ฌ์ฉํด์ผ
- list reference๊ฐ ๋ณ๊ฒฝ๋์์ ๋ recomposition ํธ๋ฆฌ๊ฑฐ๋จ
- list๊ฐ ๋ณ๊ฒฝ๋์ง ์์์ด ๋ณด์ฅ๋ ๋ ์ฌ์ฉ (ex. Room database)
val state = remember { mutableStateOf(mutableListOf("A", "B", "C")) }
state.value.add("D")
- mutable list ์ํ๋ฅผ ๊ด๋ฆฌํ ๋,
mutableStateListOf<T>
์ฌ์ฉ
val mutableList = remember { mutableStateListOf("A", "B", "C") }
state.add("D")
- ์ถ๊ฐ๋ก, Primitive ํ์
์ ์ํ ๊ด๋ฆฌ์
mutableDoubleStateOf
, mutableFloatStateOf
, mutableIntStateOf
, mutableLongStateOf
์ฌ์ฉ
mutableStateOf
์ ๋์ผํ์ง๋ง, JVM ํ๋ซํผ(ex. Android)์์ autoboxing ๋ฐฉ์งํด์ค
-> more memory efficient