Ausnahme gefangen: SSL certificate problem: certificate is not yet valid ๐Ÿ“Œ What the hell are React Server Components ?

๐Ÿ  Team IT Security News

TSecurity.de ist eine Online-Plattform, die sich auf die Bereitstellung von Informationen,alle 15 Minuten neuste Nachrichten, Bildungsressourcen und Dienstleistungen rund um das Thema IT-Sicherheit spezialisiert hat.
Ob es sich um aktuelle Nachrichten, Fachartikel, Blogbeitrรคge, Webinare, Tutorials, oder Tipps & Tricks handelt, TSecurity.de bietet seinen Nutzern einen umfassenden รœberblick รผber die wichtigsten Aspekte der IT-Sicherheit in einer sich stรคndig verรคndernden digitalen Welt.

16.12.2023 - TIP: Wer den Cookie Consent Banner akzeptiert, kann z.B. von Englisch nach Deutsch รผbersetzen, erst Englisch auswรคhlen dann wieder Deutsch!

Google Android Playstore Download Button fรผr Team IT Security



๐Ÿ“š What the hell are React Server Components ?


๐Ÿ’ก Newskategorie: Programmierung
๐Ÿ”— Quelle: dev.to

Introduction

React Server Components run only on the server. The "only" part is important here. They are designed to leverage your servers better, as described in this rfc published back around October 2022. You can think of them as Normal React Components, but that they only gets executed on server, and then they are sent to the client.

Normal React Components (when Server Rendered) are first "rendered" on the server into HTML and sent to the client (browser). Later, React adds interactivity to them (attaching event listeners to DOM elements). This process is called Hydration

In case of React Server Components, the execution process happens at the server. So, you can think like "hydration" of React Server Components happen only in the Server, the components get rendered into HTML and are sent to the client. And since, they are executed on the server, there is no need for Hydration on the client, and hence they ship without increasing your bundle side

Here is a very good visual representation for you to understand the difference between Server Side Rendering and React Server Components (Credit: @shuding_):

Server Side Rendering

Sorry, your browser doesn't support embedded videos, but don't worry, you can download it and watch it with your favorite video player!

React Server Components

Sorry, your browser doesn't support embedded videos, but don't worry, you can download it and watch it with your favorite video player!

When I should use React Server Components ?

  • One of the main use cases of RSC(s) is that you can use a large-size library (like for markdown or for date formatting, etc.) in your server, while having zero impact on your bundle size.
  import Foo from 'my-heavy-library'

  // Component that consumes Foo
  function Bar() {
    // ...Do something
  }
  // Same library, but with Server Components, zero bundle size
  import Foo from 'my-heavy-library'

  // Same component
  function Bar() {
    // ...Do something
  }
  • At other times, you might want to use env variables to access some keys, or do data fetching from your DB. You can do all that with RSC, without leaking anything in the browser source. (Well, you could do the same thing with SSR). As a general rule of thumb, if you want to use Server Resources directly, and don't want them to leak on the client, you can fetch data inside Server Components.
  async function getData() {
    const res = await fetch('https://api.example.com/...', {
      key: process.env.MY_SECRET_KEY,
    })
    // The return value is *not* serialized
    // You can return Date, Map, Set, etc.

    // Recommendation: handle errors
    if (!res.ok) {
      // ...
    }

    return res.json()
  }

  // Server Component
  export default async function Page() {
    const data = await getData()

    return <main></main>
  }
  • Using RSC, you can make sure that there are no Client Network Waterfalls. (The issue when JavaScript needs to be downloaded before a component can even start fetching data - If that component is nested deep in the component tree and parent component needs some data, then data fetching cannot even start before the child is rendered if traditional client-side rendering is used). Some libraries like Tanstack Query and React Router makes this easier by prefetching data. But still, in case of client-only rendering, you cannot fetch data before your JavaScript is downloaded.

When not to use Server Components ?

  • Server components cannot have any interactivity (onClick, onScroll, etc.) and can only be used for generating plain HTML stuff. For interactivity, you have to use what are now called Client Components.

  • Server Components cannot have state (useState) or use Side Effects (useEffect, etc). (Since the cannot have interactivity). Or custom hooks that depend on combination of state and effects.

  • Since they run on server, and server only, they cannot use browser APIs (like localStorage, etc.)

For a full comparison, check out Next.js docs for app directory

Okay, how do I use them in my app ?

...



๐Ÿ“Œ This Week In React #139: React.dev, Remix, Server Components, Error Boundary, Wakuwork, React-Native, Bottom Sheet...


๐Ÿ“ˆ 41.4 Punkte

๐Ÿ“Œ This Week In React #146: Concurrency, Server Components, Next.js, React-Query, Remix, Expo Router, Skia, React-Native...


๐Ÿ“ˆ 41.4 Punkte

๐Ÿ“Œ Typescript for React Components (or How To Write Components in React The Right Way)


๐Ÿ“ˆ 40.81 Punkte

๐Ÿ“Œ What the hell are React Server Components ?


๐Ÿ“ˆ 37.93 Punkte

๐Ÿ“Œ React Components 101: Building Reusable Components


๐Ÿ“ˆ 32 Punkte

๐Ÿ“Œ Converting React Class Components to Functional Components: A Checklist and Example


๐Ÿ“ˆ 32 Punkte

๐Ÿ“Œ ๐Ÿ”„ Class Components vs Functional Components: A Lifecycle Journey in React ๐Ÿ”„


๐Ÿ“ˆ 32 Punkte

๐Ÿ“Œ Function Components vs Class Components in React โ€“ With Examples


๐Ÿ“ˆ 32 Punkte

๐Ÿ“Œ Embracing Modern React: Transitioning from Class Components to Functional Components


๐Ÿ“ˆ 32 Punkte

๐Ÿ“Œ Embracing Modern React: Transitioning from Class Components to Functional Components


๐Ÿ“ˆ 32 Punkte

๐Ÿ“Œ React Controlled Components V/S Uncontrolled Components


๐Ÿ“ˆ 32 Punkte

๐Ÿ“Œ Introduction to Testing React Components with Vite, Vitest and React Testing Library


๐Ÿ“ˆ 29.22 Punkte

๐Ÿ“Œ React.memo - Optimize React Functional Components


๐Ÿ“ˆ 29.22 Punkte

๐Ÿ“Œ Epic Games Store: โ€žSlain: Back From Hellโ€œ und โ€žRising Hellโ€œ kostenlos


๐Ÿ“ˆ 28.29 Punkte

๐Ÿ“Œ DuckDuckGo says Hell, Hell, No to those Microsoft trackers after web revolt


๐Ÿ“ˆ 28.29 Punkte

๐Ÿ“Œ Epic Games Store: โ€žSlain: Back From Hellโ€œ und โ€žRising Hellโ€œ kostenlos


๐Ÿ“ˆ 28.29 Punkte

๐Ÿ“Œ I have had it with Microsoft. To hell with Windows. To hell with Bill Gates.


๐Ÿ“ˆ 28.29 Punkte

๐Ÿ“Œ What is The Difference Between Server Side Rendering (SSR) and React Server Components?


๐Ÿ“ˆ 27.15 Punkte

๐Ÿ“Œ This Week In React #127: Nextra, React-Query, React Documentary, Storybook, Remix, Tamagui, Solito, TC39, Rome...


๐Ÿ“ˆ 26.44 Punkte

๐Ÿ“Œ This Week In React #131: useReducer, Controlled Inputs, Async React, DevTools, React-Query, Storybook, Remix, RN , Expo...


๐Ÿ“ˆ 26.44 Punkte

๐Ÿ“Œ This Week In React #142: React-Query, Million, OpenNext, Ariakit, Expo-Image, React-Three-Fiber, TS 5.1, Node.js 20, WebGPU...


๐Ÿ“ˆ 26.44 Punkte

๐Ÿ“Œ This Week In React #137: Code Extraction, Server Components, Signals, Forget compiler, Next.js, Astro, Remix, TypeScript...


๐Ÿ“ˆ 23.78 Punkte

๐Ÿ“Œ This Week In React #136: Next.js, Signals, Bling, Suspense, Server Components, useSyncExternalStore, Expo, Reanimated, Metro...


๐Ÿ“ˆ 23.78 Punkte

๐Ÿ“Œ Internationalization In Next.js 13 With React Server Components


๐Ÿ“ˆ 23.78 Punkte

๐Ÿ“Œ How to Use React Server Components โ€“ A Beginner's Guide


๐Ÿ“ˆ 23.78 Punkte

๐Ÿ“Œ React Server Components: A comprehensive guide


๐Ÿ“ˆ 23.78 Punkte

๐Ÿ“Œ React Server-Side Components without Next.js


๐Ÿ“ˆ 23.78 Punkte

๐Ÿ“Œ This Week In React #167: Hydration, Remix, Server Components, cache, perf, Glow, Unistyles, Expo, :has(), Tailwind, date-fns...


๐Ÿ“ˆ 23.78 Punkte

๐Ÿ“Œ Streams and React Server Components


๐Ÿ“ˆ 23.78 Punkte

๐Ÿ“Œ Where do React Server Components fit in the history of web development?


๐Ÿ“ˆ 23.78 Punkte

๐Ÿ“Œ The Current State of React Server Components: A Guide for the Perplexed


๐Ÿ“ˆ 23.78 Punkte

๐Ÿ“Œ Unveiling React Server Components


๐Ÿ“ˆ 23.78 Punkte

๐Ÿ“Œ Exploring โ€œData Fetching with React Server Componentsโ€ with Next.js


๐Ÿ“ˆ 23.78 Punkte

๐Ÿ“Œ React Server Components Without a Framework


๐Ÿ“ˆ 23.78 Punkte











matomo