derivedStateOf tạo ra một state dẫn xuất được tính toán từ các state khác và chỉ recompose khi kết quả tính toán thay đổi.
Ví dụ: val isFormValid = derivedStateOf { name.isNotEmpty() && email.isNotEmpty() }. Đây là cách tối ưu để ngăn recomposition không cần thiết khi input thay đổi nhưng không ảnh hưởng đến giá trị dẫn xuất. Hữu ích cho các tính toán phức tạp trên state.
derivedStateOf creates a derived state computed from other states and only recomposes when the computed result changes.
- For example:
val isFormValid = derivedStateOf { name.isNotEmpty() && email.isNotEmpty() }. - This optimization prevents unnecessary recompositions when input changes don't affect the derived value.
- It's useful for complex computations on state.