I have a lot more slides than this. I had to cut out because I don't have time, but feel free to hit me up because optimizing for change is a fundamentally really important idea that will last way, way longer than React does.
Okay, lesson number five, test the public API. Very, very simple one. You should write tests, not too many, mostly integration. Don't test implementation detail. This is obviously very, very important for React because React undertook a huge rewrite of the whole codebase, but kept the tests and the tests actually outlasted the codebase, and that's not something that's very insightful for your apps. Obviously, they also implemented this little tracker thing for IsFiberReadyYet, where they actually tracked the completion towards the rewrite. And it's just a really motivating thing to see for the React codebase, that it's actually spread as a movement towards React apps, right? So we've seen enzyme sort of relatively declining compared to the React Testing Library, and that's as it should be, because our React Testing Library has this focus on testing only the public API of components. And that's what your users will use, and that's the only thing that you should really care about for your tests. And it makes it so much less brittle compared to what was there before.
Okay, lesson number six. We're moving along to DevTools. DevTools are not optional, and you can see how much React emphasizes DevTools. So of course, the React official DevTools, the Chrome plug-in, is maintained by Brian Vaughan on the React core team, and he does an amazing job. Like, I don't know how much I'd pay for this, but I would pay for this. And you should learn all the intricacies if you want to debug. React also uses Codemods. This is not optional for React basically because the React team actually has to maintain the tens of thousands of components that are in the Facebook codebase, and you have to upgrade all of them whenever they change the APIs, so of course you have to automate these things. And we, as the React community, get to benefit. The React Dev Warnings is something that is really taken to the limit with React. So you can see the React error overlay, or you can see lint warnings, or you can see it in the console. We even have error codes, so you can see nice errors in production, but not have extra weight in the final build artifacts, and it's a very nice decoder experience, which I wish that more developer tools copied. You can't automate everything, so it's nice to introduce some fixtures. I really like this as a way to learn React as well, because you can start to toggle on feature flags and change different browsers and see how the behavior changes. It's just a really nice way to manually test things by having everything in place so you don't have any time setting it up. And finally, the last tip is kind of like a meta-tip. DevTools to help you build DevTools. For React, because it's building a library that's going to be embedded into millions of other applications, they need to keep the bundle size small and to never increase them unintentionally, and it's something that we can actually borrow for our apps as well. We should be aware of what we're building and shipping and should be aware of big regressions.
Comments