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

React 19 - Everything you need to know

React 19 - Everything you need to know

Shruti Kapoor

November 19, 2024
Tweet

More Decks by Shruti Kapoor

Other Decks in Technology

Transcript

  1. shrutikapoor.dev shrutikapoor08 Convert a form from React 18 to React

    19 1. React Actions 2. Hooks - useActionState, useFormStatus
  2. shrutikapoor.dev shrutikapoor08 Tailwaind relative inline-flex items-center px-2 py-2 text-sm font-medium

    text-gray-500 bg-white border border-gray-300 cursor-default rounded-l-md leading-5 dark:bg-gray-800 dark:border-gray-600 relative inline-flex items-center px-4 py-2 -ml-px text- sm font-medium text-gray-700 bg-white border border-gray-300 leading-5 hover:text-gray-500 focus:z-10 focus:outline-none focus:ring ring-gray-300 focus:border-blue-300 active:bg-gray-100 active:text- gray-700 transition ease-in-out duration-150 dark:bg- gray-800 dark:border-gray-600 dark:text-gray-400
  3. 1. Skipping re-rendering of children when P a rent upd

    a tes 2. Skipping expensive c a lcul a tions Optimizations
  4. shrutikapoor.dev shrutikapoor08 1. Are you breaking Rules of React? 2.

    Try f ixing the error with “use no memo” 3. Provide feedback in GitHub Discussions.
  5. shrutikapoor.dev shrutikapoor08 •Fe a tures - Re a ct Compiler,

    Re a ct Actions •Hooks - useActionSt a te, useFormSt a tus, useOptimistic •API - use What’s new in React 19?
  6. • Better errors • Render <Context> inste a d of

    <Context.Provider> • Ref cle a nup • Met a d a t a Other updates
  7. • Better errors • Render <Context> inste a d of

    <Context.Provider> • Ref cle a nup • Met a d a t a • Stylesheets Other updates
  8. New Hooks useFormSt a tus useActionSt a te useOptimisticUI New

    Fe a tures Re a ct Actions Re a ct Compiler Upd a tes Met a d a t a Stylesheets Error logging Prelo a ding APIs P Server API Re a ct Server Components Client API st a rtTr a nsition a ccepts a sync functions
  9. • Components a nd Hooks must be pure – Purity

    m a kes your code e a sier to underst a nd, debug, a nd a llows Re a ct to a utom a tic a lly optimize your components a nd hooks correctly. • Re a ct c a lls Components a nd Hooks – Re a ct is responsible for rendering components a nd hooks when necess a ry to optimize the user experience. • Rules of Hooks – Hooks a re de f ined using J a v a Script functions, but they represent a speci a l type of reus a ble UI logic with restrictions on where they c a n be c a lled. Rules of React
  10. • Is v a lid, sem a ntic J a

    v a Script Assumptions
  11. • Is v a lid, sem a ntic J a

    v a Script • Properties a re de f ined before a ccessing them Assumptions
  12. • Is v a lid, sem a ntic J a

    v a Script • Properties a re de f ined before a ccessing them • Rules of Re a ct a re followed Assumptions
  13. 111