Fun fact: React doesn’t really “keep” class state in this.state. React keeps it internally (in the same place it now keeps state of Hooks) and assigns this.state before a component renders.
-
Show this thread
-
Think about it. When you call this.setState, React doesn’t actually update this.state immediately. That’s important for performance (batching) and features like Suspense. That’s why state is kept outside a class in a queue. Does this mean classes are _more_ magic?
14 replies 16 retweets 186 likesShow this thread -
Replying to @dan_abramov
I don't think it's necessarily a problem whether hooks are 'magical'. However I do think it's important that their misuse gives easy to understand runtime error messages and a good debugging experience. And ideally do this without the need for extra tools.
1 reply 0 retweets 1 like -
Replying to @sebinsua @dan_abramov
Actually your tweet just made me think about what people that talk about magic are really getting at. They're talking about whether they have a mental model that helps them to understand their code. And as you point out their mental models are wrong in many cases!
1 reply 0 retweets 1 like -
Replying to @sebinsua @dan_abramov
Maybe what's important is just the illusion of understanding. Or that the abstractions are a bit like the London Underground tube map (physically incorrect but helpful when getting around.)
1 reply 0 retweets 0 likes
OTOH I think this perspective of 'magic' will partially subside as they gain familiarity.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.