I am a little confused about remember function . C...
# compose-web
I am a little confused about remember function . Compare to react usememory, what's the difference?
The very first Google result for "Compose vs React" gives this - https://tigeroakes.com/posts/react-to-compose-dictionary/#usememo--remember
That page is not really helpful, because of how different state management works in Compose & React
Remember is very similar to useMemo, but useState doesn't correspond to anything
I thought
is equivalent to
remember { mutableStateOf(...) }
I mean, yes and no. In its simpler form it is, but this works:
var a by mutableStateOf(false)
Copy code
fun Foo() {
  Button(... { a = !a })
and this doesn't:
Copy code
var a by useState(false)
// “hooks cannot be used outside of functional components”
Copy code
val Foo = fc {
Essentially Compose understands state modification when you call `State`'s setter, which can happen outside of a Composable (eg. global state) without any use of remember, but React only understands state modification when the
setter is called, which can only happen locally in a component
remember + mutableStateOf
is much, much more powerful than
So if you learned React and you want to learn Compose, yes it is the equivalent, but if you come from Compose and try to learn React (like I did) it doesn't help you at all
Also, remember etc don't have anything like the rules of hooks https://reactjs.org/docs/hooks-rules.html