Logo
    Search

    React use() hook and Async Server Components Proposal

    enNovember 21, 2022

    Podcast Summary

    • React's new useDeferredValue hookReact's new hook, useDeferredValue, allows developers to optimize promise handling and write cleaner code, with potential implications for performance and developer experience.

      React, a popular JavaScript library for building user interfaces, has introduced a new hook called "useDeferredValue." This hook is designed to change the way developers write code, particularly around promises. The hosts of the Syntax podcast, Wes Bos, Barracuda, Boss, and Scott Tolinski, discuss the potential implications of this new hook and share their thoughts on it. They mention that it was a listener suggestion before the Next.js announcement, and since then, there has been a lot of chatter about it. The podcast is sponsored by two companies, Sentry and Auth0. Sentry is an error tracking tool that can help developers log, track, and resolve errors in their code, especially when using new features like this new React hook. Auth0, on the other hand, offers authentication and permission services for applications. The hosts encourage listeners to check out both sponsors and use their discount codes for additional benefits.

    • Managing authentication complexities with Auth0Auth0 simplifies authentication handling for developers, allowing them to focus on building applications while managing complexities such as multiple sign-ins and email changes.

      Handling authentication in applications can be complex due to various edge cases, such as users signing in with multiple providers, changing email addresses, or deleting accounts. Auth0 simplifies this process, making it easy for developers to handle these complexities and focus on building their applications. The speaker shared personal experiences with managing multiple Microsoft accounts associated with different services, which can be tricky to manage. In the world of React development, the community uses Request for Comments (RFCs) to discuss and decide on new features. The latest RFC is about adding first-class support for promises and async/await to React hooks. This new feature will make it easier for developers to write asynchronous code in a more concise and readable way, ultimately improving the development experience.

    • Simplifying asynchronous data calls with use hookUse hook simplifies handling asynchronous data calls by allowing components to directly use a function that returns a promise, eliminating the need for separate useEffect hooks and dependencies management.

      The new use hook proposed in React, called "use," aims to simplify handling asynchronous data calls within components. This has been a challenge in the past, requiring the use of useEffect and dealing with dependencies. The discussion also touched on React Suspense, which allows components to pause and display loaders while fetching data. Additionally, the emergence of server components and client components adds complexity. The use hook allows a component to directly use a function that returns a promise, making the process more straightforward and eliminating some of the previous complications. This can be seen in action in the new Next.js 13. Essentially, instead of using a separate useEffect for data fetching and dealing with the intricacies of resolving promises, the use hook streamlines the process by allowing the promise to be directly returned and resolved within the component itself.

    • Checking for null data in React HooksUpon first render, data fetched with hooks is null. Ensure data availability before accessing it by performing data calls on the server side, using libraries like TanStack Query, or waiting for data to resolve in React Server Components.

      It's important to check for null data when using React Hooks, especially when fetching data from APIs. Upon the first render, the data will be null, so it's crucial to ensure data availability before accessing it. One solution is to perform data calls on the server side and handle errors or missing data appropriately. This approach ensures that data is always available to components, eliminating the need for creating hooks for every data fetch. Additionally, the use of libraries like TanStack Query, which return loading state and data, can help simplify the process of handling data fetches and reduce the need for creating multiple hooks. While hooks can only be used in client components in React, the proposal for using await inside of React Server Components opens up the possibility of using database libraries and waiting for data to resolve before rendering, similar to how it's been done in PHP for decades. In essence, these approaches help streamline the process of fetching and handling data, making the development process more efficient and effective.

    • New server component feature in React introduces API usage differencesReact's new server component feature brings changes to data fetching and global promises, adding complexity and potential risks for developers

      The new server component feature in React introduces different API usage for server and client components, which can feel limiting and inconsistent for developers. The use of a special hook for data fetching in client components, as opposed to the ability to use async await directly in server components, adds complexity and exceptions to the established React rules. Additionally, React is modifying global promises by adding new fields, which has sparked concerns about potential future conflicts and compatibility issues. While some see these changes as improvements, others are skeptical about the added complexities and potential risks. It's essential to carefully consider these changes and their implications before implementing them in projects. For those interested in a deeper understanding, it's recommended to read the official proposal and weigh the benefits against the potential drawbacks.

    • Exploring React optimization techniques and historical eventsUnderstanding React's underlying mechanics, best practices, and historical events can lead to more effective and optimized development. Techniques like caching, defining functions outside of components, and using a compiler can improve performance and prevent issues.

      React and other similar frameworks can benefit from techniques like caching, defining functions outside of components, and potentially having a compiler to optimize performance and avoid issues like infinite loops. The discussion revolved around historical events like the Smooshgate incident, where developers proposed a solution called Smoosh to address issues with Flatten and flat in React. However, they ended up using flat instead. Another topic covered was the importance of defining event listeners and promises outside of components or functions to prevent infinite loops and maintain proper references. The conversation also touched upon the advantages of Svelte's API in this context due to its compiler-based approach, which allows for more efficient transformations at runtime. Overall, the key takeaway is that understanding the underlying mechanics of React and related frameworks, as well as best practices and potential improvements, can lead to more effective and optimized development.

    • Exploring the Differences and Innovations in React and SvelteThe speaker expresses excitement about the unique features and simplicity of Svelte, while also acknowledging the potential fragmentation in the React ecosystem with the recent acquisition of Remix and introduction of new features.

      The speaker is expressing excitement about the differences and innovations in various JavaScript frameworks, specifically React and Svelte. The speaker appreciates the simplicity and lack of certain concepts, such as memoization, in Svelte, which he finds refreshing. On the other hand, he currently uses server-side data loading in React and is intrigued by the potential fragmentation in the React ecosystem with the recent acquisition of Remix by Shopify and the introduction of new features like server components and suspense. The speaker also mentions the similarities between SvelteKit and Remix and wonders about the future of these frameworks. Overall, the speaker is enthusiastic about the ongoing developments in web development and the variety of options available to developers.

    Recent Episodes from Syntax - Tasty Web Development Treats

    788: Supabase: Open Source Firebase for Fullstack JS Apps

    788: Supabase: Open Source Firebase for Fullstack JS Apps

    Scott and CJ chat with Paul Copplestone, CEO and co-founder of Supabase, about the journey of building an open source alternative to Firebase. Learn about the tech stack, the story behind their excellent documentation, and how Supabase balances business goals with open-source values.

    Show Notes

    • 00:00 Welcome to Syntax!
    • 00:30 Who is Paul Copplestone?
    • 01:17 Why ‘Supa’ and not ‘Super’?
    • 02:26 How did Supabase start?
    • 08:42 Simplicity in design.
    • 10:32 How do you take Supabase one step beyond the competition?
    • 12:35 How do you decide which libraries are officially supported vs community maintained?
      • 15:17 You don’t need a client library!
    • 16:48 Edge functions for server-side functionality.
    • 18:51 The genesis of pgvector.
    • 20:59 The product strategy.
    • 22:25 What’s the story behind Supabase’s awesome docs?
    • 25:26 The tech behind Supabase.
    • 35:46 How do you balance business goals with open source?
    • 42:01 What’s next for Supabase?
    • 44:15 Supabase’s GA + new features.
    • 48:24 Who runs the X account?
    • 50:39 Sick Picks + Shameless Plugs.

    Sick Picks

    Shameless Plugs

    Hit us up on Socials!

    Syntax: X Instagram Tiktok LinkedIn Threads

    Wes: X Instagram Tiktok LinkedIn Threads

    Scott: X Instagram Tiktok LinkedIn Threads

    CJ: X Instagram YouTube TwitchTV

    Randy: X Instagram YouTube Threads

    787: You Should Try Vue.js

    787: You Should Try Vue.js

    Scott and CJ dive deep into the world of Vue.js, exploring what makes this frontend framework unique and why it stands out from React and Svelte. CJ gives a comprehensive tour, covering everything from getting started to advanced features like state management and Vue’s built-in styles.

    Show Notes

    Vue.js: The Documentary.

    Sick Picks

    Shameless Plugs

    Hit us up on Socials!

    Syntax: X Instagram Tiktok LinkedIn Threads

    Wes: X Instagram Tiktok LinkedIn Threads

    Scott: X Instagram Tiktok LinkedIn Threads

    Randy: X Instagram YouTube Threads

    786: What Open Source license should you use?

    786: What Open Source license should you use?

    Scott and CJ dive into the world of open source, breaking down its meaning, benefits, and the various types of licenses you’ll encounter. From permissive licenses like MIT and Apache 2.0 to copy-left licenses such as GNU GPLv3, they’ll help you choose and apply the right license for your project.

    Show Notes

    Hit us up on Socials!

    Syntax: X Instagram Tiktok LinkedIn Threads

    Wes: X Instagram Tiktok LinkedIn Threads

    Scott: X Instagram Tiktok LinkedIn Threads

    Randy: X Instagram YouTube Threads

    785: What’s Next for NextJS with Tim Neutkens

    785: What’s Next for NextJS with Tim Neutkens

    Scott and Wes dive into the world of Next.js with special guest Tim Neutkens from Vercel. They explore the latest updates, including the React Compiler and React Server Components, discussing their impact on developer workflows and the future of Next.js development.

    Show Notes

    • 00:00 Welcome to Syntax!
    • 00:30 What does the React Compiler do?
    • 05:04 Will React Compiler help with managing Context?
    • 06:39 What happens if you’re not using a React Compiler?
    • 09:30 Will this work on any NextJS version?
    • 12:18 What are React Server Components?
    • 16:28 Shipping all the data inside an encapsulated component.
    • 20:17 Clearing up the frustrations around retrofitting server components.
    • 23:13 Handing migration.
    • 28:30 Is this just a fetch request with props?
    • 36:41 How closely are the NextJS and React teams working?
    • 41:53 Will we ever get Async Client Components?
    • 43:52 Async Local Storage API.
    • 45:31 Turbopack.
    • 57:51 Sick Picks & Shameless Plugs.

    Sick Picks

    Shameless Plugs

    Hit us up on Socials!

    Syntax: X Instagram Tiktok LinkedIn Threads

    Wes: X Instagram Tiktok LinkedIn Threads

    Scott: X Instagram Tiktok LinkedIn Threads

    Randy: X Instagram YouTube Threads

    784: Logging × Blogging × Testing × Freelancing

    784: Logging × Blogging × Testing × Freelancing

    In this Potluck episode, Scott and Wes tackle listener questions on modern blogging, website environmental impact, and using LangChain with LLMs. They also cover CSS hyphens, unit vs. integration testing, and balancing web development with new parenthood.

    Show Notes

    Sick Picks

    Shameless Plugs

    Hit us up on Socials!

    Syntax: X Instagram Tiktok LinkedIn Threads

    Wes: X Instagram Tiktok LinkedIn Threads

    Scott: X Instagram Tiktok LinkedIn Threads

    Randy: X Instagram YouTube Threads

    783: How We Built a Netflix Style “Save for Offline” Feature Into Syntax

    783: How We Built a Netflix Style “Save for Offline” Feature Into Syntax

    Scott and Wes dive into the world of browser caching for audio files, exploring the File System API and the Cache API. They discuss size restrictions across different browsers, how tools like Riverside.fm leverage IndexedDB, and walk through code examples for creating, retrieving, and managing cached audio data.

    Show Notes

    Hit us up on Socials!

    Syntax: X Instagram Tiktok LinkedIn Threads

    Wes: X Instagram Tiktok LinkedIn Threads

    Scott:X Instagram Tiktok LinkedIn Threads

    Randy: X Instagram YouTube Threads

    782: The Developer’s Guide To Fonts with Stephen Nixon

    782: The Developer’s Guide To Fonts with Stephen Nixon

    Scott and CJ are joined by Stephen Nixon of ArrowType to delve into the world of fonts and type for developers. They explore the intricacies of font creation, the utility of variable fonts, and offer tips for making visually appealing typography on the web.

    Show Notes

    Sick Picks

    Shameless Plugs

    Hit us up on Socials!

    Syntax: X Instagram Tiktok LinkedIn Threads

    Wes: X Instagram Tiktok LinkedIn Threads

    Scott:X Instagram Tiktok LinkedIn Threads

    Randy: X Instagram YouTube Threads

    781: Potluck - The Value of TypeScript × Vue vs Svelte × Leetcode

    781: Potluck - The Value of TypeScript × Vue vs Svelte × Leetcode

    In this potluck episode of Syntax, Scott and CJ serve up a variety of community questions, from the nuances of beginner vs. advanced TypeScript to the pros and cons of SvelteKit. They also discuss falling out of love with React, shipping private packages via NPM, and the eternal struggle of always starting but never finishing projects.

    Show Notes

    Sick Picks

    Shameless Plugs

    Hit us up on Socials!

    Syntax: X Instagram Tiktok LinkedIn Threads

    Wes: X Instagram Tiktok LinkedIn Threads

    Scott:X Instagram Tiktok LinkedIn Threads

    Randy: X Instagram YouTube Threads

    780: Cloud Storage: Bandwidth, Storage and BIG ZIPS

    780: Cloud Storage: Bandwidth, Storage and BIG ZIPS

    Today, Scott and Wes dive into cloud storage solutions—why you might need them, how they use them, and what you need to know about the big players, fees, and more.

    Show Notes

    Hit us up on Socials!

    Syntax: X Instagram Tiktok LinkedIn Threads

    Wes: X Instagram Tiktok LinkedIn Threads

    Scott:X Instagram Tiktok LinkedIn Threads

    Randy: X Instagram YouTube Threads

    779: Why SQLite is Taking Over with Brian Holt & Marco Bambini

    779: Why SQLite is Taking Over with Brian Holt & Marco Bambini

    Scott and CJ dive into the world of SQLite Cloud with special guests Brian Holt and Marco Bambini. They explore why SQLite is gaining traction, its unique features, and the misconceptions surrounding its use—let’s get into it!

    Show Notes

    • 00:00 Welcome to Syntax!
    • 01:20 Who is Brian Holt?
    • 02:26 Who is Marco Bambini?
    • 05:12 Why are people starting to talk so much about SQLite now?
    • 08:47 What makes SQLite special or interesting?
    • 09:46 What is a big misconception about SQLite?
    • 11:13 Installed by default in operating systems.
    • 12:03 A perception that SQLite is intended for single users.
    • 13:36 Convincing developers it’s a full-featured solution.
    • 15:11 What does SQLite do better than Postgres or MySQL?
    • 17:30 SQLite Cloud & local first features.
    • 20:38 Where does SQLite store the offline information?
    • 23:08 Are you typically reaching for ORMs?
    • 25:00 What is SQLite Cloud?
    • 27:29 What makes for an approachable software?
    • 29:18 What make SQLite cloud different from other hosted SQLite options?
    • 32:13 Is SQLite still evolving?
    • 34:40 What about branching?
    • 37:37 What is the GA timeline?
    • 40:04 How does SQLite actually work?
    • 41:19 Questions about security.
    • 44:28 But does it scale?
    • 45:52 Sick Picks + Shameless Plugs.

    Sick Picks

    Brian: Trainer Road
    Marco: Tennis

    Shameless Plugs

    Hit us up on Socials!

    Syntax: X Instagram Tiktok LinkedIn Threads

    Wes: X Instagram Tiktok LinkedIn Threads

    Scott:X Instagram Tiktok LinkedIn Threads

    Randy: X Instagram YouTube Threads

    Related Episodes

    686: We Need Your Help With The Secret Sauce

    Mégalodon : le grand carnassier disparu était bien plus svelte que le requin blanc

    Mégalodon : le grand carnassier disparu était bien plus svelte que le requin blanc
    durée : 00:04:57 - Avec sciences - par : Alexandra Delbot - Seules les dents et quelques vertèbres d'Otodus megalodon - son vrai nom ! - ont traversé les âges. Faute de mieux, le grand requin blanc a souvent servi de modèle pour les reconstitutions. Une nouvelle étude réexamine des restes et conclut que sa morphologie était bien différente.

    2021 In Review

    2021 In Review

    In this episode of Syntax, Scott and Wes review their predictions and highlights for 2021.

    .TECH Domains - Sponsor

    .TECH is taking the tech industry by storm. A domain that shows the world what you are all about! If you're looking for a domain name for your startup, portfolio, or your own project like we did with uses.tech, check out .tech Domains. Syntax listeners can snap their .TECH Domains at 80% off on five-year registration by visiting go.tech/syntaxistech and using the coupon code "syntax5".

    Sentry - Sponsor

    If you want to know what’s happening with your code, track errors and monitor performance with Sentry. Sentry’s Application Monitoring platform helps developers see performance issues, fix errors faster, and optimize their code health. Cut your time on error resolution from hours to minutes. It works with any language and integrates with dozens of other services. Syntax listeners new to Sentry can get two months for free by visiting Sentry.io and using the coupon code TASTYTREAT during sign up.

    Mux - Sponsor

    Mux Video is an API-first platform that makes it easy for any developer to build beautiful video. Powered by data and designed by video experts, your video will work perfectly on every device, every time. Mux Video handles storage, encoding, and delivery so you can focus on building your product. Live streaming is just as easy and Mux will scale with you as you grow, whether you're serving a few dozen streams or a few million. Visit mux.com/syntax.

    Show Notes

    ××× SIIIIICK ××× PIIIICKS ×××

    Shameless Plugs

    Tweet us your tasty treats

    Tech To Watch In 2020

    Tech To Watch In 2020

    In this episode of Syntax, Scott and Wes talk about tech to watch in 2020 — things you should keep an eye on and learn this year!

    Sanity - Sponsor

    Sanity.io is a real-time headless CMS with a fully customizable Content Studio built in React. Get a Sanity powered site up and running in minutes at sanity.io/create. Get an awesome supercharged free developer plan on sanity.io/syntax.

    LogRocket - Sponsor

    LogRocket lets you replay what users do on your site, helping you reproduce bugs and fix issues faster. It’s an exception tracker, a session re-player and a performance monitor. Get 14 days free at logrocket.com/syntax.

    Show Notes

    6:39 - CSS Subgrid

    8:10 - CSS Houdini

    11:20 - CSS features not supported in older browsers yet

    • Scrollsnap - IE 11 and up. Lot’s of mobile issues.
    • position:sticky - no IE at all

    14:24 - NPM tink

    • installer-less npm
    • Load packages at runtime into a shared cache across all projects
    • Intelligently download the parts you need

    17:25 - Yarn PnP

    • Hard links to eliminate package duplication
    • Shared cache across all projects

    18:31 - Pika & Snowpack

    21:10 - Deno

    • New Node?

    25:39 - React

    • Suspense in more libraries
    • Suspense for Server Rendering
    • Meteor
      • New ownership. v1.9 just dropped with lots of promise for future growth
    • Svelte 3
    • Vue 3
    • Apollo
    • Next.js

    36:37 - Serverless

    • Going to get easier
    • Begin.com
    • Next.js / Now Functions

    38:14 - Gatsby

    • A single useQuery (made possible by suspense)

    39:36 - Headless CMS Thunderdome

    42:20 - Next Gen Frameworks

    • Keystone
    • Strapi
    • Meteor
    • Vulcan.js

    43:46 - Cypress

    • End to end testing
    • Currently no Firefox support, but hopeful for 2020

    44:21 - Modulz

    • Exports to JS component

    45:00 - Figma

    • Was already amazing in 2019
    • Constantly improving and adding new features
    • Can import from Sketch

    Links

    ××× SIIIIICK ××× PIIIICKS ×××

    Shameless Plugs

    Tweet us your tasty treats!