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

TechTalk 2o22 - State of React State Management

TechTalk 2o22 - State of React State Management

As a Front-end developer, one of the most crucial skills to possess is how to manage the state of your applications. The ability to synchronize application states with data changes and manage shared states amongst different components is a vital requirement in building modern front-end applications. Several state management libraries have been developed with certain frameworks that naturally work well with a de-facto state management library. In this lecture, you will learn all the most common state management alternatives.

Marko Arsić

August 31, 2022
Tweet

More Decks by Marko Arsić

Other Decks in Programming

Transcript

  1. HypeTech Tech education and shaping ideas into hype products hypetech.io

    | reactweek.dev Marko Arsić Founder and CEO @ HypeTech Founder of HypeTech Education Senior Software Engineer @ adidas Lecturer @ ReactWeek.dev Independent Tech Consultant Helping companies set up teams and standardize the development process github.com/marsicdev
  2. No New Features Primarily focused on making it easier to

    upgrade React itself Easier to embed React into apps built with other technologies
  3. Before React 18, React already batched (aka grouped) multiple state

    updates into one to reduce unnecessary re-renders.
  4. Automatic Batching it happened only in DOM event handlers, so

    Promises, timeouts, or other handlers didn’t take advantage of that.
  5. React components have a built-in state object. The state is

    encapsulated data where you store assets that are persistent between component renderings.
  6. If a user changes state by interacting with your application,

    the UI may look completely different afterwards, because it's represented by this new state.
  7. Persistent State - lives on the server and it is

    accessible, for example, via a REST endpoint
  8. Navigation State - where is the user in the application?

    Is he on the sign-in page, the sign-up page or the profile page?
  9. Local UI State - what is the colour of the

    button? Is the panel expanded or not? Is the modal open
  10. Client State - filters selected by the user when dealing

    with a large list of items, the current page in the list of items, table sorting, pagination, infinite scroll
  11. Context is designed to share data that can be considered

    “global” for a tree of React components
  12. Context is primarily used when some data needs to be

    accessible by many components at different nesting levels
  13. If you only want to avoid passing some props through

    many levels, component composition is often a simpler solution than context
  14. RTK Query - Takes inspiration from other tools that have

    pioneered solutions for data fetching, like Apollo Client, React Query, Urql, and SWR, but adds a unique approach to its API design
  15. • The data fetching and caching logic is built on

    top of Redux Toolkit • RTK Query's functionality can be used with any UI layer • RTK Query can also generate React hooks that encapsulate the entire data fetching process
  16. Fetch, cache and update data in your React and React

    Native applications all without touching any "global state".
  17. With Apollo's declarative approach to data fetching, all of the

    logic for retrieving your data, tracking loading and error states, and updating your UI is encapsulated by the useQuery Hook.
  18. SWR

  19. SWR is a strategy to first return the data from

    cache (stale), then send the fetch request (revalidate), and finally come with the up-to-date data.
  20. 1. Identify the type of state 2. Keep your state

    data as close as possible benefits: maintainability and performance. 3. Don't keep your entire state globally benefits: increased complexity, hard to maintain
  21. As the application is starting to grow, so does the

    complexity of managing the state.
  22. you should plan for it because it can be the

    decisive factor for the success or failure of your application
  23. Q & A As everything good in life, knowledge is

    great only when shared https://discord.gg/94uhCAkFKf