<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Adaptive Shield Matrix</title>
    <description>The latest articles on DEV Community by Adaptive Shield Matrix (@adaptive-shield-matrix).</description>
    <link>https://dev.to/adaptive-shield-matrix</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F635983%2Fcf7548e7-db84-44a1-9242-42b2bebd5130.png</url>
      <title>DEV Community: Adaptive Shield Matrix</title>
      <link>https://dev.to/adaptive-shield-matrix</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/adaptive-shield-matrix"/>
    <language>en</language>
    <item>
      <title>React Basics: Essential Knowledge for Every React Developer</title>
      <dc:creator>Adaptive Shield Matrix</dc:creator>
      <pubDate>Sun, 12 Nov 2023 11:53:20 +0000</pubDate>
      <link>https://dev.to/adaptive-shield-matrix/react-basics-essential-knowledge-for-every-react-developer-2096</link>
      <guid>https://dev.to/adaptive-shield-matrix/react-basics-essential-knowledge-for-every-react-developer-2096</guid>
      <description>&lt;p&gt;This post is meant to cover essential information that every react developer should know or be aware of.&lt;/p&gt;

&lt;p&gt;Another article name could be "Most common problems encountered in React"&lt;/p&gt;

&lt;p&gt;Why is this important? &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Since React is not really a framework and only a view library it does not offer an all-in-one solution to most web development needs and relies on its ecosystem to round out its rough edges.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Most common problems in react frontend development are&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Typescript usage with React&lt;/li&gt;
&lt;li&gt;When and how to use core APIs and Hooks&lt;/li&gt;
&lt;li&gt;State Management&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because not knowing the basics (especially for beginners) leads to countless repeat of mistakes, confusion, suffering &lt;br&gt;
and complaining loudly on the internet about how frontend development in general and react in particular sucks (even if it is not true).&lt;/p&gt;

&lt;h2&gt;
  
  
  Basics / Fundation
&lt;/h2&gt;

&lt;p&gt;You don't require any paid courses for react frontend development if your read through and have a strong grasp of the following resources&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Javascript&lt;/strong&gt; - &lt;a href="https://javascript.info/"&gt;https://javascript.info/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Typescript&lt;/strong&gt; - &lt;a href="https://www.typescriptlang.org/docs/handbook/2/basic-types.html"&gt;https://www.typescriptlang.org/docs/handbook/2/basic-types.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;React&lt;/strong&gt; - &lt;a href="https://react.dev/"&gt;https://react.dev/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;React with TypeScript&lt;/strong&gt; - &lt;a href="https://github.com/typescript-cheatsheets/react"&gt;https://github.com/typescript-cheatsheets/react&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Tsconfig
&lt;/h2&gt;

&lt;p&gt;Enable strict typescript compiler settings&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;strict&lt;/code&gt; is most important&lt;/li&gt;
&lt;li&gt;Other entries after that are optional&lt;/li&gt;
&lt;li&gt;I disabled &lt;code&gt;noUnusedLocals&lt;/code&gt; and &lt;code&gt;noUnusedParameters&lt;/code&gt; in my projects because It more often gets in the way than helps (especially if you refactor code more often)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;tsconfig.json&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"compilerOptions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;code&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;quality&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;settings&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"strict"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"noUncheckedIndexedAccess"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"noUnusedLocals"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"noUnusedParameters"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"noImplicitAny"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"noImplicitReturns"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"noFallthroughCasesInSwitch"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"forceConsistentCasingInFileNames"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read about the individual fields here&lt;br&gt;
&lt;a href="https://www.totaltypescript.com/tsconfig-cheat-sheet"&gt;https://www.totaltypescript.com/tsconfig-cheat-sheet&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  React core APIs to avoid
&lt;/h2&gt;

&lt;p&gt;Hooks that should only be used in library code (if your write public or internal ones) and avoided in web app code&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;useContext&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;useRef&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;useId&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Try to avoid and use only rarely / then necessary&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;useEffect&lt;/code&gt; - Why? Best explanation - &lt;a href="https://react.dev/learn/you-might-not-need-an-effect"&gt;https://react.dev/learn/you-might-not-need-an-effect&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Avoid and do not use following hooks&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;use&lt;/code&gt;, &lt;code&gt;useState&lt;/code&gt;, &lt;code&gt;useContext&lt;/code&gt; -&amp;gt; Replaced by custom methods provided by the state management library&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;useMemo&lt;/code&gt;, &lt;code&gt;useCallback&lt;/code&gt;, &lt;code&gt;cache&lt;/code&gt; -&amp;gt; The most common premature optimization addressing re-render issues, which are unnecessary and can be skipped completely if using a proper state management library&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  React State Management
&lt;/h2&gt;

&lt;p&gt;React build-in core libraries offer only primitives like &lt;code&gt;useState&lt;/code&gt; and &lt;code&gt;useContext&lt;/code&gt; to manage state.&lt;br&gt;
React evolved over the years and relies heavily on its community to cover its weaknesses, particularly in the realm of state management.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why are the build-in hooks &lt;code&gt;useState&lt;/code&gt; and &lt;code&gt;useContext&lt;/code&gt; not good enough?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;They are ment to be primitives, meant to be extended&lt;/li&gt;
&lt;li&gt;They work only good enough in a single isolated component&lt;/li&gt;
&lt;li&gt;Are are inadequate to pass and share state across multiple components&lt;/li&gt;
&lt;li&gt;All above incentivises you to write very big components (-&amp;gt; that are hard to read), 
since passing state between components causes uneccesary re-renders and bad performance&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Why are the build-in hooks &lt;code&gt;useState&lt;/code&gt; and &lt;code&gt;useContext&lt;/code&gt; not good enough to share state between components?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using &lt;code&gt;useState&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;Causes you to pass down state from parent components to child component by props&lt;/li&gt;
&lt;li&gt;Having to pass down additional functions to change said state (from parents to child components)&lt;/li&gt;
&lt;li&gt;If a child component calls a state mutation function (passed from a parent) -&amp;gt; the parent and all of its child have to re-render -&amp;gt; performance problems&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Using &lt;code&gt;useContext&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;You will have a high amount of wrapped &lt;code&gt;&amp;lt;A..Provider&amp;gt;&amp;lt;B..Provider&amp;lt;/B..Provider&amp;gt;&amp;lt;/A..Provider&amp;gt;&lt;/code&gt; Context Providers that makes it hard to read and follow thats going on&lt;/li&gt;
&lt;li&gt;Modifing state of a single context providers -&amp;gt; forces a reload of all components using this context&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Both &lt;code&gt;useState&lt;/code&gt; and &lt;code&gt;useContext&lt;/code&gt; cause unnecessary re-render that are hard to track down&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here are this and more react problems mentioned in more detail if you want to read futher&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React I Love You, But You're Bringing Me Down - &lt;a href="https://marmelab.com/blog/2022/09/20/react-i-love-you.html"&gt;https://marmelab.com/blog/2022/09/20/react-i-love-you.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Comments on Hacker News - &lt;a href="https://news.ycombinator.com/item?id=32911492"&gt;https://news.ycombinator.com/item?id=32911492&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Commends on Reddit - &lt;a href="https://www.reddit.com/r/reactjs/comments/xja3y5/react_i_love_you_but_youre_bringing_me_down/"&gt;https://www.reddit.com/r/reactjs/comments/xja3y5/react_i_love_you_but_youre_bringing_me_down/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What is the best way to manage state in React?
&lt;/h3&gt;

&lt;p&gt;The industry-accepted solution to re-render problems is a signal based state manager.&lt;br&gt;
Learning from Reacts quirks (and mistakes) newer frameworks like Solid.js and Svelte have incorporated signal based state management into their core libraries.&lt;/p&gt;

&lt;p&gt;As of now, React doesn't come equipped with a built-in signal based state manager. &lt;br&gt;
Consequently, a significant number of new React developers, myself included (then I started), encounter the problems stemming from the issues mentioned above.&lt;/p&gt;

&lt;p&gt;How to do state in react the right way&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use Query/Search URL parameters for saving and loading web app state.

&lt;ul&gt;
&lt;li&gt;This should be the first and default choice&lt;/li&gt;
&lt;li&gt;Simplifying sharing with others and troubleshooting problems yourself&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Combine state with data fetching with &lt;a href="https://tanstack.com/query"&gt;react-query&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;This should be the second choice since you have to fetch data anyway&lt;/li&gt;
&lt;li&gt;Skip this option if you are using &lt;a href="https://trpc.io/"&gt;trpc&lt;/a&gt; or prefer not to use &lt;code&gt;react-query&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Using a signal based state manager

&lt;ul&gt;
&lt;li&gt;Allows updating only the parts that change, called atomic updates&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://jotai.org/"&gt;jotai&lt;/a&gt; Is the signal based state manager I recommended, offering the best developer experience (in my opinion) as it eliminates the necessity to define and update a global store&lt;/li&gt;
&lt;li&gt;Or use one of the other signal based state manager libraries: Zustand, Valtio, React-Redux, Recoil, etc&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is a more detailed comparison of react state manager libraries&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The new wave of React state management - &lt;a href="https://frontendmastery.com/posts/the-new-wave-of-react-state-management/"&gt;https://frontendmastery.com/posts/the-new-wave-of-react-state-management/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Comments Hacker News - &lt;a href="https://news.ycombinator.com/item?id=31959289"&gt;https://news.ycombinator.com/item?id=31959289&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Comments on reddit - &lt;a href="https://www.reddit.com/r/javascript/comments/vpsuzt/the_new_wave_of_react_state_management/"&gt;https://www.reddit.com/r/javascript/comments/vpsuzt/the_new_wave_of_react_state_management/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Futher reading
&lt;/h2&gt;

&lt;p&gt;Checkout the following link about the React ecosystem for routing, form handling, UI component, animation libraries and more&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React Ecosystem in 2024 - &lt;a href="https://dev.to/avinashvagh/react-ecosystem-in-2024-418k"&gt;https://dev.to/avinashvagh/react-ecosystem-in-2024-418k&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Do I need a fetching library in React?</title>
      <dc:creator>Adaptive Shield Matrix</dc:creator>
      <pubDate>Wed, 27 Jul 2022 10:37:43 +0000</pubDate>
      <link>https://dev.to/adaptive-shield-matrix/do-i-need-a-fetching-library-in-react-4j1g</link>
      <guid>https://dev.to/adaptive-shield-matrix/do-i-need-a-fetching-library-in-react-4j1g</guid>
      <description>&lt;h2&gt;
  
  
  Assumptions
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;server state - as a single source of truth&lt;/li&gt;
&lt;li&gt;you want/need CSR&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What does a fetching library do?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;tracking loading and error state (ui spinner or notification/toast on error)&lt;/li&gt;
&lt;li&gt;deduplicate requests (prevent race conditions, minimize requests)&lt;/li&gt;
&lt;li&gt;manage cache (precisely control then to keep or revalidate data)&lt;/li&gt;
&lt;li&gt;automatically re-fetch (on tab switching, network loss, periodically, pc/laptop sleep)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Why do I need deduplication?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;if using React.strictMode (remounts all components twice, -just for fun- to be future proof for upcoming parallel rendering)&lt;/li&gt;
&lt;li&gt;if calling the same API across multiple components&lt;/li&gt;
&lt;li&gt;if opening the app in multiple tabs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Why do I need to manage the cache?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;for fast/faster ui performance&lt;/li&gt;
&lt;li&gt;to reduce server load or completely prevent an unresponsive/overloaded server&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Why do I need automatic re-fetching?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;if you experience a network disconnect and reconnect (data on the server may have changed)&lt;/li&gt;
&lt;li&gt;if your pc/laptop goes to sleep and wakes up (a long time may have passed)&lt;/li&gt;
&lt;li&gt;if you leave the tab open and browse elsewhere (again, a long time may have passed)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to fetch
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;directly using (&lt;a href="https://beta.reactjs.org/learn/you-might-not-need-an-effect"&gt;fetch/axios&lt;/a&gt;)

&lt;ul&gt;
&lt;li&gt;(-) diy: ignore remounting in React.strictMode&lt;/li&gt;
&lt;li&gt;(-) diy: isLoading&lt;/li&gt;
&lt;li&gt;(-) diy: isError&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;useFetch (&lt;a href="https://usehooks-ts.com/react-hook/use-fetch"&gt;use-fetch&lt;/a&gt;)

&lt;ul&gt;
&lt;li&gt;(+) loading state&lt;/li&gt;
&lt;li&gt;(+) separate result and error states&lt;/li&gt;
&lt;li&gt;(+) reusable&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;useSWR (&lt;a href="https://swr.vercel.app/"&gt;swr&lt;/a&gt;)

&lt;ul&gt;
&lt;li&gt;(+) built-in (in memory) cache&lt;/li&gt;
&lt;li&gt;(+) request deduplication - can call same api in multiple components&lt;/li&gt;
&lt;li&gt;(+) re-fetch/revalidate on focus - then switching windows/tabs&lt;/li&gt;
&lt;li&gt;(+) re-fetch/revalidate on network recovery - internet loss or then laptop goes to sleep&lt;/li&gt;
&lt;li&gt;(+) local mutation, optimistic UI updates&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;useQuery (&lt;a href="https://github.com/tannerlinsley/react-query"&gt;react-query&lt;/a&gt;)

&lt;ul&gt;
&lt;li&gt;(+) all from above&lt;/li&gt;
&lt;li&gt;(+) even more features&lt;/li&gt;
&lt;li&gt;(-) more complex, even the examples are complex, has more aggressive defaults (re-fetching every 2s)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Redux Query (&lt;a href="https://redux-toolkit.js.org/rtk-query/overview"&gt;rkt-query&lt;/a&gt;)

&lt;ul&gt;
&lt;li&gt;skipped / not analyzed, 
since I already got burned by Redux's verbosity/complexity/overengineering on its introduction&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Web app architecture
&lt;/h2&gt;

&lt;p&gt;A fetching library influences how you structure a web app, it incentivizes you to structure your code in a way, that isn't obvious at first sight.&lt;/p&gt;

&lt;p&gt;Web app architectures&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;centralized, top-to-bottom&lt;/li&gt;
&lt;li&gt;decentralized, multiple fetch calls from different components&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Centralized, top-to-bottom web arch&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;parent/root fetches all data and passes it down with prop drilling or react context&lt;/li&gt;
&lt;li&gt;recommended by official React docs [&lt;a href="https://beta.reactjs.org/learn/you-might-not-need-an-effect#passing-data-to-the-parent"&gt;1&lt;/a&gt;]&lt;/li&gt;
&lt;li&gt;the most simple approach, works beautifully in small apps&lt;/li&gt;
&lt;li&gt;very easy to reason about and debug&lt;/li&gt;
&lt;li&gt;my recommendation: write a custom API that delivers all needed data in one fetch call, 1 api for each page&lt;/li&gt;
&lt;li&gt;may not be possible in more complex web apps or if some parts need to be refreshed quite often &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Decentralized web arch&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;each component fetches its own data&lt;/li&gt;
&lt;li&gt;the only way to structure highly complex web apps&lt;/li&gt;
&lt;li&gt;deduplication is a must-have feature -&amp;gt; a fetching library is required to be used&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Downsides of using a fetching library
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;does not work with PWA / offline-first apps

&lt;ul&gt;
&lt;li&gt;local/offline changes may/will be overwritten by fetching old server state&lt;/li&gt;
&lt;li&gt;may be circumvented / 
(-&amp;gt; need to write own custom logic -&amp;gt; how?)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;CSR vs SSR: CSR may be more work than SSR.

&lt;ul&gt;
&lt;li&gt;in SSR you just simply directly call the db and pass the ready data to the UI&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  (Not-)Alternatives
&lt;/h2&gt;

&lt;p&gt;If applicable (no highly dynamic content)&lt;br&gt;
consider using&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;SSR&lt;/li&gt;
&lt;li&gt;Centralized, top-to-bottom web arch&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;SSR&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;is a much simpler approach and&lt;/li&gt;
&lt;li&gt;you do not need to care about fetching or writing APIs at all&lt;/li&gt;
&lt;li&gt;because all the calls happen on the server and you do not need to do extensive validation (or need to do less of it)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Centralized, top-to-bottom web arch&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;make custom APIs for each ui page&lt;/li&gt;
&lt;li&gt;to minimize ui api calls and return all needed data at once&lt;/li&gt;
&lt;li&gt;managed by the most parent/container/wrapper&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Side notes
&lt;/h2&gt;

&lt;p&gt;fetching libraries can act or even replace a state manager&lt;br&gt;
how?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;with mutate -&amp;gt; you can trigger change state of others&lt;/li&gt;
&lt;li&gt;if you change url/key -&amp;gt; data will be refetched&lt;/li&gt;
&lt;li&gt;you always get current data from the hook&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;why?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;if you can reduce the amount of code and/or complexity it is always worth it
(if it is possible to do, and you do not rely on state-manager features that are crucial to your web app)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Terminology
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;ui - User interface&lt;/li&gt;
&lt;li&gt;db - Database&lt;/li&gt;
&lt;li&gt;offline-first - web app works completely normal without an internet connection&lt;/li&gt;
&lt;li&gt;PWA - Progressive Web Apps&lt;/li&gt;
&lt;li&gt;arch - Architecture&lt;/li&gt;
&lt;li&gt;CSR - Client Side Rendering&lt;/li&gt;
&lt;li&gt;SSR - Server Side Rendering&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>nextjs</category>
      <category>performance</category>
    </item>
  </channel>
</rss>
