One thing that I really love about React's API design is over time, it has really folded itself away into the language and just felt more native to the runtime that you're running in. So instead of doing extend React component, you create a function, instead of doing create element, you have JSX. And with server components, you have this opportunity to write components which feel very ergonomic, where you're writing async in a way, and you're fetching data, and it just feels really a lot like JavaScript. But then that created this kind of asymmetry between server and client, where on the client you still have a ton of hooks to do things like use memo, and so you're writing components which just look very different. And now with React Compiler, you're able to fold a lot of those hooks away, and it makes it a little bit more symmetric across server and client, and it feels more native to the platform, even though compiler does make React feel more like its own programming language than previously. But I think that's great, because the hooks, they kind of sometimes break your mental model, and this leaning more into it makes it feel very native to what you're writing.
Yeah, following up with that, I'm curious to see if there's a bit of a sense of loss with like, oh, I learned all this knowledge of how to write, use memo correctly, and how to memoize all my stuff by hand. It's similar to me to all the state management libraries and stuff. I was very into that. And they're still very useful for a lot of things, but I way overused state management, and then once I started using Remix, and we just had a very simple loader component action kind of model, and it was pretty easy to do ephemeral mutations and all this kind of stuff. I just stopped caring about state, and it felt like a little bit of a loss, but then at the end I was really happy, and I kind of wonder if the compiler's going to do the same thing. It's like, oh no, but all my knowledge, and it's like, oh, I don't actually need that knowledge, and it's really nice that I don't need that. I can now fill my head with more useless knowledge. Yeah, it's interesting that you say that, because Satya saw me last night about handmade memoizations and how React Compiler is just far more performant. Yeah, so with the use memo hook, you can't call it conditionally. It needs to be at the statement level, but the compiler can compile values within a conditional, so it's more... I really don't want to say fine-grained, but... Careful. It is more fine-grained, less granular than a use memo, and it does... The other problem with manual memorization is it can be brittle if you're not careful, and you miss memorizing one value, that can cascade down all your components and cause re-rendering of everything. But with the React Compiler, the compiler is way better at making sure every single value is memorized, so your components are more stable, and they don't re-render more often. Yeah, at Facebook, for example, we have engineers who work on performance and have spent a lot of time thinking about optimizing product code with use memos. And when we wanted to ship the compiler, we thought it would be like a DX win, and the performance would be the same. But we actually saw better performance, and we also saw that the performance increased so much that it led to engagement wins on the product. So it is definitely a lot more than manual memorization, at least on a reasonably-sized app when you have multiple people working on it. I see lots of head nods on the stage, which is always a good thing to see as well. It's exciting. It's so exciting. Drop it in, and your app becomes more performant. Yeah.
Comments