Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Batching, Suspense, and Server Components

Batching, Suspense, and Server Components

Sendil Kumar N

April 21, 2022
Tweet

More Decks by Sendil Kumar N

Other Decks in Programming

Transcript

  1. @sendilkumarn Agenda • Batching • What, Why, & How? •

    Gotchas • Suspense in SSR • What, Why, & How? • Gotchas • Server Components • What, Why, & How? • Gotchas
  2. @sendilkumarn Batching is when React groups multiple state updates into

    a single re-render for a better performance Batching - What?
  3. @sendilkumarn Batching - Why? • Better performance • No unnecessary

    re-renders • Consistent User Experience • No weird intermediate state
  4. @sendilkumarn Batching - Gotchas • React ensures the user initiated

    event (like click / keypress) is properly handled & processed before the next event. So do not worry about two submissions of a form. • React only batched updates when it is safe to do.
  5. @sendilkumarn <Suspense /> lets you wait for code to load

    & specify the load state. Suspense - What?
  6. @sendilkumarn SSR - How it works? 17 Finish Fetch Finish

    loading Finish Hydrate Then Interact
  7. @sendilkumarn Suspense in SSR - How it works? <Layout> <Header

    /> <Main> <Post /> <Comments /> </Main> <Footer /> </Layout> Server Side Rendered 18
  8. @sendilkumarn Suspense in SSR - How it works? <Layout> <Header

    /> <Main> <Post /> <Suspense> <Comments /> </Suspense> </Main> <Footer /> </Layout> Suspend the load 18
  9. @sendilkumarn Suspense in SSR - What’s exciting? • Load the

    page before all the code is loaded • Hydrate the page before all the HTML is streamed • Interacting with the page with all the components have been hydrated
  10. @sendilkumarn Suspense in SSR - Gotchas • Hydration happens within

    the <Suspense /> context • Always Parent- fi rst order • React holds o ff from dispatching events until the entire parent tree • Opt-in component
  11. @sendilkumarn Server Components - How it works? Server Runs only

    on Server Database FileSystem APIs Faster…
  12. @sendilkumarn Server Components - How it works? Dependencies / libraries

    are free Server rendering will remove these dependencies Only rendered HTML will go to the client
  13. @sendilkumarn Server Components - How it works? No Interactivity 🚫

    No Use State No User Events ✅ Import client.js Send in props