Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why can't I remember mutableStateOf Composable Function directly?

I can have

val composeFunction = remember { mutableStateOf ({}) }

I can have

val composeFF = @Composable { Text("ABC") }
val composeFunction = remember { mutableStateOf (composeFF) }

Why can’t I have

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

val composeFunction = remember { mutableStateOf (@Composable { Text("ABC") }) }

It errors out state

Internal Error occurred while analyzing this expression 
(Please use the "
 
" icon in the bottom-right corner to report this error):
 
jar:file:/Applications/Android%20Studio.app/Contents/lib/platform-impl.jar!/general/error.svg
Type inference failed. Expected type mismatch: inferred type is @Composable () -> Unit but () -> Unit was expected

>Solution :

Have you tried specifying the type?

val composeFunction = remember { mutableStateOf<@Composable () -> Unit> (@Composable { Text("ABC") }) }

Looks like the compiler cannot infer an ordinary function to something that is supplied with a @Composable annotation

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading