Latest / CyberSecurity Summary / React in Depth
Transcript
- 0:00Speaker 1: If you're a React developer, or maybe just you know,
- 0:02Speaker 1: really curious about how these cutting edge web applications get built,
- 0:06Speaker 1: you've probably felt this. Oh yeah, the React ecosystem is
- 0:09Speaker 1: just huge. It's this sprawling, constantly evolving universe. It really is,
- 0:13Speaker 1: And it's easy to feel a bit lost right with
- 0:16Speaker 1: all the tools, the libraries, the best practices changing all
- 0:19Speaker 1: the time.
- 0:20Speaker 2: Absolutely, you might see a job posting with like a
- 0:22Speaker 2: dozen technologies you've barely heard of. It can feel pretty overwhelming,
- 0:27Speaker 2: like trying to map a whole galaxy totally.
- 0:30Speaker 1: Well, today we're diving in. Our mission here is to
- 0:33Speaker 1: try and turn that feeling of overwhelm into well confidence,
- 0:38Speaker 1: confident understanding.
- 0:39Speaker 2: Sounds like a plan.
- 0:40Speaker 1: We're digging deep into an incredible source, the book React
- 0:45Speaker 1: in Depth by Morton Berkland. He's a staff engineer at Quirky,
- 0:48Speaker 1: a medical AI startup, and has get this over two
- 0:52Speaker 1: decades in front end development.
- 0:53Speaker 2: Wow. Yeah, it's a seriously insightful book. So we're going
- 0:56Speaker 2: to pull out the most critical bits, maybe uncover some
- 0:59Speaker 2: surprising facts along the way.
- 1:01Speaker 1: Exactly, and help you connect the dots across some pretty
- 1:03Speaker 1: complex topics.
- 1:04Speaker 2: Think of this as your personal guide navigating the React universe,
- 1:09Speaker 2: pointing out the really important stars you should probably focus on.
- 1:12Speaker 1: Okay, let's start with that vast ecosystem. Then the book
- 1:15Speaker 1: calls it a vast collection of libraries and tools, not
- 1:19Speaker 1: just React itself, but everything orbiting it. It feels massive,
- 1:23Speaker 1: it does.
- 1:24Speaker 2: But what's interesting, I think is that tools in the
- 1:26Speaker 2: same category aren't always just competitors. Oh yeah, the book
- 1:30Speaker 2: says some augment one another, so you might actually use
- 1:33Speaker 2: several together in one project.
- 1:35Speaker 1: Like what give me an example.
- 1:36Speaker 2: Okay, take testing. You could easily use just for your
- 1:40Speaker 2: unit tests, React Testing library for you know, checking how
- 1:43Speaker 2: components render, maybe Puppeteer for end to end stuff, and
- 1:47Speaker 2: Karma for browser testing.
- 1:49Speaker 1: Ah okay, so they all have their own job within
- 1:51Speaker 1: testing exactly.
- 1:52Speaker 2: They play different roles in like a complete testing strategy.
- 1:55Speaker 1: So what does this mean for you the listener, when
- 1:58Speaker 1: you're scanning job posts or maybe kicking off a new project.
- 2:02Speaker 1: How do you make sense of it all?
- 2:03Speaker 2: Well, that really brings us to understanding the technology stack.
- 2:06Speaker 2: It's super important, right, yeah, it defines the specific tools
- 2:09Speaker 2: chosen for that project.
- 2:11Speaker 1: Yeah.
- 2:11Speaker 2: I mean the term full stack developer literally comes from
- 2:14Speaker 2: someone working across the whole thing front in the back end.
- 2:17Speaker 1: Right, it's how all those individual pieces, those libraries and
- 2:20Speaker 1: tools fit together to make something that actually works precisely.
- 2:24Speaker 1: And we're talking about a lot here. UI libraries like material,
- 2:27Speaker 1: UI tailwind, CSS, uh.
- 2:29Speaker 2: Huh, cssn JS, things like styled components.
- 2:32Speaker 1: Data management tools like redex Toolkit.
- 2:34Speaker 2: Or zoos stand, even authentication providers AUTHO, Firebase, stuff like that.
- 2:39Speaker 1: In the book gives examples, right, like different kinds of stacks.
- 2:42Speaker 2: Yeah, it does. It mentions an enterprise stack maybe React
- 2:45Speaker 2: with typescript, Apollo for data, style components for styling, you know,
- 2:49Speaker 2: focused on robustness. We're maybe a rapid prototyping stack using
- 2:53Speaker 2: tools like next JS, Redwood JS or remix, where the
- 2:56Speaker 2: priority is speed overcrafting a totally unique U.
- 3:00Speaker 1: Gotcha. Okay, So moving from that big picture ecosystem down
- 3:05Speaker 1: to the nitty gritty blueprints, let's talk about building stable,
- 3:08Speaker 1: scalable REACT projects. The book highlights three core design patterns, provider, composite,
- 3:15Speaker 1: and summary.
- 3:16Speaker 2: Yes, these are fundamental.
- 3:17Speaker 1: Can you walk us through though, starting with provider.
- 3:19Speaker 2: Sure, the provider pattern is, well, it's way more than
- 3:22Speaker 2: just a minor thing. It's really foundational for how you
- 3:26Speaker 2: distribute and organize data and functionality across your whole app.
- 3:30Speaker 1: Distribute data so avoiding prop.
- 3:33Speaker 2: Drilling exactly, that's a huge part of its genius. No
- 3:37Speaker 2: more passing props down ten levels when only the bottom
- 3:40Speaker 2: component needs it. Nightmare.
- 3:42Speaker 1: Ugh yeah, been there right.
- 3:44Speaker 2: A provider lets you just inject that global stuff, user off, theme, settings, whatever,
- 3:49Speaker 2: directly where it's needed. Cleans up the component tree massively.
- 3:53Speaker 1: Makes refractoring easier too, I bet totally.
- 3:55Speaker 2: And you might have like dozens of contexts on many
- 3:58Speaker 2: layers for global, starf or even local features. There are
- 4:02Speaker 2: even tools like recontextual the book mentions to help manage that,
- 4:05Speaker 2: especially with types.
- 4:06Speaker 1: Okay, that makes a lot of sense. So building on that,
- 4:09Speaker 1: what about the composite pattern how does that help structure components?
- 4:12Speaker 2: Right? Composite, So imagine a really complex component, say a
- 4:16Speaker 2: radio group, instead of building one giant, monolithic.
- 4:19Speaker 1: Thing which can get messy fast.
- 4:21Speaker 2: Exactly, the composite pattern says, break it down, makes smaller subcomponents,
- 4:25Speaker 2: maybe a radio group itself, a radio option or radio.
- 4:29Speaker 1: Label, and they talk to each other.
- 4:30Speaker 2: Yeah, they communicate using contexts often provided by the main
- 4:34Speaker 2: wrapper component. The book says this leads to cleaner, more
- 4:37Speaker 2: readable code that's easier.
- 4:39Speaker 1: To maintain, transforming those rigid structures.
- 4:42Speaker 2: Into something flexible, scalable. It's like a harmonious symphony. As
- 4:46Speaker 2: the book puts, it makes components reusable. Let's developers compose
- 4:51Speaker 2: UIs really flexibly nice?
- 4:53Speaker 1: Okay. Third one, the summary pattern. What's the goal with
- 4:56Speaker 1: that one?
- 4:57Speaker 2: Summary is all about giving your components a makeover, making
- 5:02Speaker 2: them look more streamlined, sophisticated. Basically, you pack the complex logic,
- 5:06Speaker 2: the business logic, into custom hooks like use task list
- 5:10Speaker 2: or use new task input.
- 5:12Speaker 1: Ah. So you pull the logic out of the main
- 5:14Speaker 1: component body exactly.
- 5:15Speaker 2: You tidy up all that code above the JSX return statement.
- 5:18Speaker 2: It simplifies the component file itself a lot, makes collaboration
- 5:21Speaker 2: easier because the component's interface is just cleaner, more readable.
- 5:24Speaker 2: You separate the what's from the how cool?
- 5:27Speaker 1: Okay, let's shift gears performance. This is a big one.
- 5:30Speaker 1: Often chops people up. Why react components rerender?
- 5:34Speaker 2: Ah? Yes, the classic question.
- 5:36Speaker 1: There's this common idea, right that they rerender just because
- 5:39Speaker 1: their probs change. But the book says, flat out changing
- 5:43Speaker 1: properties is irrelevant.
- 5:44Speaker 2: Yeah, that myth needs busting, it's not why they rerender.
- 5:47Speaker 1: So if that's wrong, what are the actual rules when
- 5:51Speaker 1: does a component rerender? Okay?
- 5:52Speaker 2: The book is very clear here. It says a component
- 5:54Speaker 2: only rerenders if one it's just been mounted, two its
- 5:58Speaker 2: parent component just re rendered, or three it uses a
- 6:01Speaker 2: hook like use state or use reducer that has flagged
- 6:04Speaker 2: the component for a rerender.
- 6:06Speaker 1: That's it, Just those three.
- 6:07Speaker 2: That's it. It contradicts that common idea about props and
- 6:10Speaker 2: highlights some subtle timing things react handles internally. Not understanding
- 6:15Speaker 2: this can lead to performance headaches.
- 6:17Speaker 1: Right, So, knowing those rules, how do we actually make
- 6:20Speaker 1: our apps faster? Minimize those and necessary it renders? That
- 6:24Speaker 1: brings us to memoization, doesn't it?
- 6:26Speaker 2: Ya?
- 6:26Speaker 1: It does.
- 6:26Speaker 2: Memorization is key. It's basically remembering the last input and
- 6:31Speaker 2: output of a pure function to avoid doing expensive calculations
- 6:34Speaker 2: again if the input hasn't.
- 6:36Speaker 1: Changed, like cashing the result.
- 6:38Speaker 2: Pretty much, And this applies to components using memo or
- 6:41Speaker 2: specific values with used memo or functions with use callback
- 6:45Speaker 2: strategic caching to stop redundant work.
- 6:48Speaker 1: Okay, and speaking of use memo and use callback, yeah,
- 6:51Speaker 1: those dependency arrays, they can be tricky.
- 6:54Speaker 2: Oh yeah, getting them right is crucial both for performance
- 6:57Speaker 2: and correctness.
- 6:58Speaker 1: So what exactly counts as a dependency? What goes in
- 7:01Speaker 1: the array? Good question?
- 7:03Speaker 2: The book clarifies it's any local variable that exists inside
- 7:06Speaker 2: the component's scope.
- 7:08Speaker 1: Not stuff from outside right imports?
- 7:10Speaker 2: Nope, not variables from outside the component, not imports. That's
- 7:13Speaker 2: a common confusion point, and crucially, sometimes you can even
- 7:16Speaker 2: skip listing variables if they're guaranteed to be stable. Stable
- 7:20Speaker 2: like what like the set open function you get back
- 7:22Speaker 2: from you state it never changes, so you don't technically
- 7:25Speaker 2: need to list it. Knowing that can make your dependency
- 7:28Speaker 2: arrays cleaner and easier to understand. Prevents unnecessary reruns too.
- 7:32Speaker 1: Huh. Okay, that's useful detail. All right, Let's look beyond
- 7:36Speaker 1: just the React code itself. How do we ensure quality, consistency,
- 7:41Speaker 1: effective collaboration. The book gives four guideposts linting, formatting, property constraints,
- 7:48Speaker 1: and debugging.
- 7:49Speaker 2: Yeah, the tooling and practices around the code.
- 7:52Speaker 1: Let's start with linting. What's its job?
- 7:54Speaker 2: Think of linting using tools like es lint as like
- 7:58Speaker 2: a smart grammar checker for your code. Okay, it helps
- 8:01Speaker 2: catch potential errors that come from JavaScript's quirks. You know,
- 8:04Speaker 2: it's language weirdness, and it enforces team best practices.
- 8:09Speaker 1: And it can fix things automatically.
- 8:11Speaker 2: A huge percentage. Yeah, it can fix a huge percentage
- 8:13Speaker 2: of these violations automatically. Cash is stuff early streamlines development
- 8:17Speaker 2: quite a bit.
- 8:18Speaker 1: Okay. Then there's formatting, usually with Prettier. How's that different
- 8:20Speaker 1: from linting linting check style too?
- 8:22Speaker 2: Sometimes it does, but Prettier focuses only on formatting, and
- 8:25Speaker 2: the book says it's smart. It doesn't just follow simple
- 8:28Speaker 2: rules blindly moving smart. It adapts dynamically to the code
- 8:32Speaker 2: in question, using whatever formatting looks best for readability. It
- 8:37Speaker 2: basically ends the subjective arguments about code style. Let the tool.
- 8:41Speaker 1: Handle It takes the debate out.
- 8:43Speaker 2: Of it, exactly, And the book also mentions editor can
- 8:46Speaker 2: fig for basic stuff like indentation, line endings, foundational rules
- 8:51Speaker 2: that work across different editors.
- 8:53Speaker 1: Got it, So code Thatt's good follows practices. What about
- 8:56Speaker 1: property constraints? Is that like prop types?
- 8:58Speaker 2: Yeah? Exactly? Using reacts built in prop type system it
- 9:02Speaker 2: makes your components more robust and easier to use because
- 9:04Speaker 2: you specify what kind of props, they expect types ranges
- 9:08Speaker 2: maybe if.
- 9:09Speaker 1: They're required, and this helps at runtime.
- 9:10Speaker 2: Yeah, it flags issues at runtime if a component gets
- 9:13Speaker 2: used incorrectly. It's older than Typescript sure, but still offers
- 9:17Speaker 2: valuable run time checks and serves as documentation.
- 9:20Speaker 1: Okay, but even with all that, bugs happen, oh, inevitably
- 9:24Speaker 1: so debugging. The book really emphasizes the React developer tools absolutely.
- 9:29Speaker 2: Their power is that you're working right there in the
- 9:31Speaker 2: live browser environment.
- 9:32Speaker 1: What can you do with them?
- 9:33Speaker 2: You can inspect and manipulate component props, check the values
- 9:37Speaker 2: in stateful hooks, and crucially use the profiler to dig
- 9:41Speaker 2: into performance issues see what's re rendering and why.
- 9:44Speaker 1: And there are other tools too, loads.
- 9:47Speaker 2: Specialized ones like reducs dev tools if you're using reducs,
- 9:50Speaker 2: React Native debugger, React to Tron for electron apps, even
- 9:53Speaker 2: replay dot io for time travel, debugging aerror sessions a
- 9:57Speaker 2: whole arsenal.
- 9:58Speaker 1: Really wow, Okay, now's hit a topic that's huge for
- 10:01Speaker 1: many developers.
- 10:03Speaker 2: Typescript uh typescript.
- 10:05Speaker 1: Yes, the book calls it your bridge to a world
- 10:08Speaker 1: where code becomes more predictable and maintainable. How does it
- 10:11Speaker 1: do that? Well?
- 10:13Speaker 2: Fundamentally, It adds spatic types to JavaScript right, which significantly
- 10:17Speaker 2: reduces the likelihood of runtime errors. Things that would crash
- 10:20Speaker 2: your app in production get caught during development. Plus, it
- 10:23Speaker 2: simplifies collaboration on larger codebases. How So, because the types
- 10:27Speaker 2: act as documentation, you can define union types, interfaces, optional properties.
- 10:32Speaker 2: It brings clarity and confidence, especially when multiple people are
- 10:35Speaker 2: working on complex code.
- 10:36Speaker 1: And the core concept in typescript is generics, right, how
- 10:40Speaker 1: do they help? In React?
- 10:41Speaker 2: Generics are super powerful. They let you create versatile components
- 10:45Speaker 2: that can adapt to different types of content, like a
- 10:48Speaker 2: reusable component exactly. Imagine one pageantable component that works perfectly
- 10:53Speaker 2: for a list of employees and a list of high scores.
- 10:56Speaker 2: Generics make that possible and type safe, and.
- 10:58Speaker 1: You can manipulate types two.
- 11:00Speaker 2: With omit and pick right, you can take an existing
- 11:03Speaker 2: interface and omit certain properties or pick just the ones
- 11:07Speaker 2: you need when extending. It gives you really granular control
- 11:10Speaker 2: over your type definitions. Makes components both powerful and precisely typed.
- 11:14Speaker 1: Okay, so when you use typescript with React toos, you
- 11:18Speaker 1: state use memo, use callback. Are there any common gotcha's
- 11:22Speaker 1: things to watch out for?
- 11:23Speaker 2: Definitely? With you state. You got to be mindful of
- 11:26Speaker 2: initial values that might change type later, like starting is
- 11:29Speaker 2: null exactly null boolean for instance, you need to tell
- 11:32Speaker 2: Typescript that's possible. And while use memo and use callback
- 11:35Speaker 2: are pretty good at inferring types, there are edge cases. Yeah,
- 11:39Speaker 2: edge cases like using forward ref or memo with generic components.
- 11:44Speaker 2: Sometimes Typescript kind of forgets the generic types, so you
- 11:47Speaker 2: might need to give explicit type arguments or use something
- 11:50Speaker 2: called global type augmentation to remind it. Otherwise you lose
- 11:54Speaker 2: the type safety you wanted good to know.
- 11:56Speaker 1: Yeah. The book also mentions the new React compiler.
- 11:59Speaker 2: Yeah Briefly. It suggests the compiler might make explicit memorization
- 12:04Speaker 2: with use memo and use callback less critical in the future,
- 12:07Speaker 2: which could simplify some of this exciting stuff but still evolving.
- 12:11Speaker 1: Interesting. Okay, let's switch focus again Styling CSS and React.
- 12:15Speaker 1: The book talks about the entire reason why CSS and
- 12:18Speaker 1: JS exists. What was wrong with traditional CSS?
- 12:22Speaker 2: Well, the core problem CSS and JS really tries to
- 12:24Speaker 2: solve is collisions. Name collisions right like class names exactly
- 12:29Speaker 2: as your app grows. The book says collisions are likely
- 12:31Speaker 2: because CSS is global by default, you can only have
- 12:34Speaker 2: one class named dot group anywhere in your app, and.
- 12:37Speaker 1: Someone else might use the same name accidentally.
- 12:39Speaker 2: Precisely, leading to styles overwriting each other unexpectedly MESSI. That's
- 12:45Speaker 2: where things like CSS modules came in first, generating unique
- 12:49Speaker 2: class names automatically scoping styles to components right to prevent
- 12:54Speaker 2: those accidental conflicts.
- 12:55Speaker 1: But the book seems to lean more towards styled components
- 12:59Speaker 1: as a popular modern approach.
- 13:01Speaker 2: It does highlight it. Yeah, styled components lets you literally
- 13:04Speaker 2: write your CSS directly inside your JavaScript files, right next
- 13:08Speaker 2: to the components using those styles. Callocation big benefit. Offers
- 13:12Speaker 2: a much better overview of small components. Plus you get
- 13:15Speaker 2: dynamic styling based on props true encapsulation. It's kind of
- 13:18Speaker 2: the default choice for many teams.
- 13:20Speaker 1: The IBM of styling, the book says.
- 13:22Speaker 2: Uh huh, Yeah, nobody gets fired for using it. It's
- 13:25Speaker 2: widely adopted, battle tested, but it's not perfect. No approaches.
- 13:29Speaker 2: The book mentions potential drawbacks like maybe slower build times,
- 13:33Speaker 2: and some argue it blurs the separation of concerns.
- 13:35Speaker 1: Too much, so no single best way.
- 13:38Speaker 2: The book's takeaway is clear, there is no one best
- 13:41Speaker 2: way to style a React application. It really depends on
- 13:44Speaker 2: the project, the team. The requirements makes sense.
- 13:47Speaker 1: Okay, data management, we've touched on U state, but for
- 13:50Speaker 1: really big complex apps you need more, right. The book
- 13:53Speaker 1: uses a goal tragging app example to explore five approaches.
- 13:57Speaker 2: Right beyond just U state or use reducer context, you
- 14:01Speaker 2: have libraries like Redux Toolkit, zoostand x state offering more structure.
- 14:06Speaker 1: What about Immer. You mentioned that with used reducer h Immer.
- 14:09Speaker 2: Yeah, it's often used with US reducer or Redux Toolkit.
- 14:12Speaker 2: It drastically simplifies writing immutable updates. It lets you write
- 14:16Speaker 2: code that looks like you're directly mutating the state, which
- 14:19Speaker 2: you normally shouldn't do exactly, but Immer cleverly intercepts those
- 14:23Speaker 2: mutations and produces a new immutable state object behind the scenes.
- 14:28Speaker 2: The book uses this cool analogy like dark matter. You
- 14:31Speaker 2: don't see the complex mechanics, but it clearly works and
- 14:34Speaker 2: gives you clean immutable state.
- 14:36Speaker 1: That's a neat way to think about it. Now. A
- 14:38Speaker 1: more advanced idea of the book covers is state machines
- 14:42Speaker 1: using x state. That sounds like more than just data storage.
- 14:45Speaker 2: Oh much more. Xdate isn't just about what data you have.
- 14:48Speaker 2: It's about defining the explicit flow of a complex.
- 14:51Speaker 1: Operation, like a user sign up flow.
- 14:53Speaker 2: Perfect example, a multi step signup X state lets you
- 14:58Speaker 2: model all the possible states, entering email, verifying CODs, setting passwords,
- 15:03Speaker 2: and the transitions between them. It makes complex flows much
- 15:07Speaker 2: more predictable and prevents impossible states. You still manage data
- 15:11Speaker 2: within the machine's context, but the focus is on the flow.
- 15:14Speaker 1: Okay, so we have context, redux, zoo stand x state.
- 15:18Speaker 1: How do you choose?
- 15:19Speaker 2: Yeah, that's the million dollar question, isn't it?
- 15:22Speaker 1: It seems like it.
- 15:22Speaker 2: Well, the book notes reducs is still one of the
- 15:24Speaker 2: most used huge community lots of tooling zoostand is described
- 15:28Speaker 2: as maybe the easiest library to use for such a
- 15:31Speaker 2: tiny application because it's simpler, less boilerplate. But ultimately, ultimately,
- 15:35Speaker 2: if you have the choice, the book basically says, go
- 15:38Speaker 2: with whatever is most comfortable for you. Team, familiarity, project needs,
- 15:42Speaker 2: the actual complexity of your state. Those factors usually guide
- 15:45Speaker 2: the decision.
- 15:46Speaker 1: Right, makes sense? Okay, connects to the outside world remote data.
- 15:49Speaker 1: Modern apps almost always talk to server almost always, Yeah,
- 15:52Speaker 1: and the book points out that server complexity brings challenges, latency, security.
- 15:57Speaker 2: Issues, definitely. And this is where library is like tan
- 16:00Speaker 2: stat query formally react query really help.
- 16:02Speaker 1: How do they help?
- 16:03Speaker 2: They formalize things, They structure how you handle remote data
- 16:06Speaker 2: around this common dichotomy queries versus mutations.
- 16:10Speaker 1: Queris fetch data, mutations change it exactly.
- 16:13Speaker 2: Queries fetch, mutations, create, update, delete, And they employ smart
- 16:18Speaker 2: caching strategies like stale wall revalidate, stale wall revalidate.
- 16:22Speaker 1: What's that It means?
- 16:23Speaker 2: If you need data, the library gives you the cached
- 16:27Speaker 2: stale version immediately, so the UI updates fast. Then in
- 16:31Speaker 2: the background it refetches the fresh data from the server
- 16:33Speaker 2: and updates the cash balances responsiveness and freshness clever.
- 16:38Speaker 1: So when there is a delay waiting for the server,
- 16:41Speaker 1: what does that mean for the user? How do we
- 16:42Speaker 1: make that waiting less painful?
- 16:44Speaker 2: Good question. For any noticeable delay, say over one hundred milliseconds,
- 16:48Speaker 2: the book says you absolutely need loading indicators, spinner's progress bar.
- 16:52Speaker 1: Something standard practice.
- 16:54Speaker 2: Yeah, but even better the book suggests are optimistic.
- 16:58Speaker 1: Updates optimist stick. How does that work?
- 17:01Speaker 2: You basically pretend the server requests succeeded immediately you update
- 17:05Speaker 2: the local cash with what we expect the server to
- 17:08Speaker 2: do before you get the confirmation back.
- 17:10Speaker 1: Ah, so the UI updates.
- 17:11Speaker 2: Instant it feels instant. Yeah, perceived instant feedback. If the
- 17:15Speaker 2: server request fails later you roll back the change, But
- 17:18Speaker 2: most of the time it makes the app feel incredibly snappy.
- 17:22Speaker 1: Cool trick. What about partial data?
- 17:24Speaker 2: That's another technique, also called initial data. You show a
- 17:27Speaker 2: skeleton view like gray boxes where text will be or
- 17:31Speaker 2: maybe a description with dots instead of the full text,
- 17:34Speaker 2: missing timestamps perhaps while you wait for the full data.
- 17:37Speaker 2: Gives the user something to see immediately improves perceived performance.
- 17:40Speaker 1: Lots of ways to handle latenciesm okay. Last major topic, testing,
- 17:45Speaker 1: how do we make sure our apps are solid, reliable,
- 17:48Speaker 1: future proof against bugs? Unit testing absolutely trucial.
- 17:52Speaker 2: The book focuses on using vitised and React testing library.
- 17:56Speaker 1: Why those specifically.
- 17:57Speaker 2: Because they encourage writing tests focused on test resilience, tests
- 18:01Speaker 2: that don't break if the JSX changed in even the
- 18:03Speaker 2: slightest way.
- 18:04Speaker 1: So testing behavior not implementation details exactly.
- 18:08Speaker 2: Focus on functionality. Does clicking this button do the right thing?
- 18:13Speaker 1: Not?
- 18:13Speaker 2: Does this button contain this exact CSS class? And the
- 18:17Speaker 2: user Event library is highlighted as great for simulating realistic
- 18:21Speaker 2: user actions, clicking typing makes tests reflect actual usage.
- 18:25Speaker 1: Okay, but components often depend on other things, right, Yeah,
- 18:28Speaker 1: APIs context. How do you test them in isolation? That
- 18:32Speaker 1: brings up mocking dependencies.
- 18:34Speaker 2: Yes, mocking is essential for true unit testing. How do
- 18:38Speaker 2: you test your component without external factors messing things up
- 18:41Speaker 2: or making the test unreliable?
- 18:43Speaker 1: So what can you mock?
- 18:44Speaker 2: You can mock browser APIs like maybe navigator, dot geolocation
- 18:47Speaker 2: if your component uses location. You can mock libraries like
- 18:50Speaker 2: axios if you're making API calls. Or you can even
- 18:53Speaker 2: mock a context provider to give your component specific context
- 18:56Speaker 2: data just for the test.
- 18:58Speaker 1: So you control the environment.
- 18:59Speaker 2: Completely ensure as you're only testing your component's logic, no
- 19:03Speaker 2: flaky tests due to network issues or changes in external services.
- 19:07Speaker 2: Gives you real confidence.
- 19:08Speaker 1: Makes sense? Yeah? Okay. Let's wrap up by looking at
- 19:10Speaker 1: the really big picture building complete web experiences with React,
- 19:15Speaker 1: specifically server side rendering or SSR.
- 19:19Speaker 2: Right, moving beyond client only React.
- 19:21Speaker 1: What's the big win with running React on the server.
- 19:24Speaker 2: The main advantage is it allows you to run React
- 19:26Speaker 2: on the server to generate the initial HTML. This enables
- 19:30Speaker 2: full stack development with React.
- 19:32Speaker 1: One codebase for front and back.
- 19:34Speaker 2: End potentially yeah, or at least much tighter integration. You
- 19:38Speaker 2: get optimal collocation of rendering, logic and data fetching, potentially
- 19:42Speaker 2: simplifying things like API layers, brings the whole stack closer together.
- 19:46Speaker 1: But there's a catch, right, something called hydration.
- 19:48Speaker 2: Ah Yes, hydration crucial detail. It's the process where the
- 19:52Speaker 2: client side Ravascript basically takes over the HTML sent by
- 19:55Speaker 2: the server, attaching event listeners and making it interactive. And
- 19:59Speaker 2: for the performance benefit of SSR to work, the HTML
- 20:01Speaker 2: rented on the client must be identical to the HTML
- 20:04Speaker 2: sent by the server.
- 20:05Speaker 1: What happens if it's not.
- 20:06Speaker 2: If hydration fails, there's a mismatch. React basically throws away
- 20:11Speaker 2: the server HTML and rerenders the entire page from scratch
- 20:14Speaker 2: on the client, which can actually be slower than just
- 20:17Speaker 2: doing a client side render in the first place oach.
- 20:19Speaker 1: So getting hydration.
- 20:21Speaker 2: Right is key absolutely. The book also mentions partial hydration
- 20:25Speaker 2: as a newer sort of bleeding edge idea to improve this,
- 20:28Speaker 2: only hydrating necessary parts of the page.
- 20:30Speaker 1: Interesting okay, and the book looks at two big frameworks
- 20:34Speaker 1: for doing this next, doutch As and Remix, two of
- 20:37Speaker 1: the most popular Yeah, what are the key differences? The
- 20:39Speaker 1: book points out well.
- 20:40Speaker 2: Next js is often described as optimized for hosting speed
- 20:43Speaker 2: and performance, especially with its platform, ver sell great for
- 20:47Speaker 2: static sites, complex apps, and Remix. Remix emphasizes JavaScript independence,
- 20:52Speaker 2: meaning core features often work even if JavaScript fails or
- 20:56Speaker 2: is disabled in the browser. Offers a more robust baseline.
- 20:59Speaker 1: Any other different diferences like routing.
- 21:01Speaker 2: Yeah, the book notes their different conventions for dynamic routes
- 21:05Speaker 2: employee dot js and Next versus EMPLOYEEJS and Remix and
- 21:09Speaker 2: also Remix moving to a flatter routing structure in V
- 21:12Speaker 2: two index dot jsx instead of index dot jsx just
- 21:16Speaker 2: shows how these powerful frameworks keep evolving the best practices.
- 21:20Speaker 1: Wow, okay, we have covered a ton of ground today.
- 21:23Speaker 2: We really have a proper deep dive.
- 21:25Speaker 1: We explored that huge React ecosystem, dove into advanced component
- 21:29Speaker 1: patterns like provider and composite, tackled performance optimization and mammalization.
- 21:35Speaker 2: Talk to essential developer tools, linting, formatting, debugging, the power.
- 21:39Speaker 1: Of typescript, modern styling with CSS and JS. Robust data
- 21:43Speaker 1: management strategies from reducs to x state.
- 21:46Speaker 2: Handling remote data smartly with caching, and optimistic updates, building
- 21:50Speaker 2: confidence with resilient unit testing, and.
- 21:52Speaker 1: Finally the world of full stack React frameworks like NEXTJS
- 21:55Speaker 1: and Remix with SSR and hydration QW. Yeah.
- 21:58Speaker 2: As the book puts it, the reacting of system is extensive,
- 22:01Speaker 2: it's constantly changing, and.
- 22:02Speaker 1: Critically, knowledge is most valuable when understood and applied.
- 22:06Speaker 2: Couldn't agree more so.
- 22:07Speaker 1: After this journey through reacts depths, the question for you
- 22:10Speaker 1: is what part of this mastery will you explore next?
- 22:14Speaker 1: What will you apply to build your most robust, your
- 22:16Speaker 1: most scalable, or your most performant React application yet