Deep Dive on React Hooks Architecture

Bookmark
Rate this content

Have you ever wonder how React hooks work on the inside? There is a lot of magic going on, like functions being able to store state. How is that possible?

Join me and let's do a quick deep dive into how React hooks work on the inside.

This talk has been presented at React Summit US 2025, check out the latest edition of this React Conference.

FAQ

A React Fiber is a unit of work on a component that needs to be done or was done, used to manage updates and rendering in React's reconciliation process.

Mattermos is an open source collaboration tool focused on mission-critical scenarios.

Mattermos's mobile and web apps are written in React, using mostly functional components.

JSX is a syntax that allows writing HTML inside JavaScript, which is transformed into React.createElement calls by a transpiler.

Importing React is necessary in a JSX file because the transpiler converts JSX into React.createElement calls, which requires React to be in the context.

React hooks, like useState, manage state by creating hook objects and linked lists in memory, using global variables for performance optimization.

The React scheduler organizes and performs work on fibers by dividing tasks into units of work, preventing process starvation and managing updates efficiently.

When a function component is rendered, it returns a React.createElement, which is used to build a fiber tree for rendering on the DOM.

The cost of using hooks in React involves CPU usage depending on dependencies and updates, as well as memory usage for storing hook objects and states.

Hooks must be called in the same order to ensure that the correct memoized state is used, preventing issues due to the linked list structure in React's implementation.

Daniel Espino García
Daniel Espino García
25 min
21 Nov, 2025

Comments

Sign in or register to post your comment.
Video Summary and Transcription
Introduction to React Hooks and Architecture with insights into Mattermos, React components, and JSX syntax. Understanding React.createElement, React components, and createRoot for DOM rendering. Exploring React rendering process and scheduler's role in managing component work units. Exploring React fiber tree creation and hook mechanism for state management. Exploring React fiber tree mount and update mechanisms with global variable orchestration. Exploring the use of global variables for performance optimization and the process of callback updating in React Fiber tree. Exploring hook rules and different hook mechanisms like useRef and useEffect in React. Effects in React fiber, useState complexity, update mechanisms, and cost considerations. Memory storage considerations for hooks, impact on CPU, and style optimization. Insights into React Fiber storage of props and style comparisons. Summary of topics covered and acknowledgment of additional details for future exploration.

1. Introduction to React Hooks and Architecture

Short description:

Introduction to React Hooks and Architecture with insights into Mattermos, React components, and JSX syntax.

♪ Hello, everyone, and welcome to Deep Dive on React Hooks and Architecture. My name is Daniel Espino Garcia, a software design engineer at Mattermos. So what is Mattermos? Mattermos is an open source collaboration tool focused on mission-critical scenarios, but that is not what is important for this talk. The important thing for this talk is that both the mobile and the web app are written in React, and they use mostly functional components. So, yeah, that's what we use.

And why am I talking about this? Well, I'm an engineer. I like to break things and see how they are inside. And with the magic of open source, I can do that with React. I can go directly to the source code and see all that magic around hooks, about how functions can store a state and stuff like that. How does all that work? So I was curious about it. I researched it and I made a talk out of that.

So before we start, all the rebel bug images during the talk are AI generated. That's why they are not the most consistent thing. I have no relationships at all with the React team. I am just a guy that is looking into the code and getting to conclusions. So I don't know the exact reasons why things were done one way or the other, and I may be understanding things wrong from the code. So everything I've shown here is based on what I found in this repo, in the React repo. And finally, at some point, I got a stack and I had to look for help outside, and I found this blog post that was really interesting to understand how all the fiber thing works. And that was able to get me back on track. But, well, without further ado, what are we going to see? Well, we are going to see, our train is going to go from the component. We write our function component to the render, how it gets into the screen. But in order to do that, we have to get a longer path. First of all, we have to understand what is JSX. We understand what is JSX, we will have to understand what is React element, then what is a fiber. Then we will have a better understanding of what is our component, which will lead us to understanding hooks, which will lead us back into fibers and how all that renders. So let's start with that. What is JSX? JSX is just writing HTML inside JavaScript. And what is all that? It's just syntax server. The transpiler handles all this. And with a tool like this one, you can get the result.

2. Understanding React.createElement and createRoot

Short description:

Understanding React.createElement, React components, and createRoot for DOM rendering.

And the result is a lot of React.createElement. So as you can see, your function, what it does is do a React.createElement and return that. That's all it does. So, interesting thing. You must import React. Because if the transpiler substitutes things to React.createElement, it needs React to be in the context. That's why you get so often these errors like, hey, you are in JSX file and you haven't imported React. You have to import React. This is why. Actually, there's a new runtime that, in theory, gets rid of that. But, yeah, I haven't looked deep into that.

So we have this React.createElement. That's what our function component is returning. But what is actually a React.createElement? So if we go to this part of the code, we see that React.createElement is just an object. The component itself is not even called. The component is going to be stored in type. So type will store a function, our function component. So, okay, if our component is not yet called, when is my function component called? Well, okay, so we have components that just return a React.createElement. And if we go up that tree, we will get to the root.

And the root, according to a template, should be something like this, React.createRoot, and then root.render. So let's focus on the first part, on createRoot. What does that do? It creates a host root. A host root fiber. So what is a fiber? A fiber is work on a component that needs to be done or was done. That is the definition they have in the code, in some comments. So, okay, it's work on a component that needs to be done or was done. And what the host root part means? It's a reference to a root in the host system. The host system, in our case, will be the DOM. Okay. We are creating this root that has a reference to somewhere in the DOM, and then we are calling render.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

You Can’t Use Hooks Conditionally… or Can You?
React Summit 2023React Summit 2023
28 min
You Can’t Use Hooks Conditionally… or Can You?
Top Content
Watch video: You Can’t Use Hooks Conditionally… or Can You?
The Talk discusses the use of the Use hook in React and its ability to be used conditionally. It explains the concept of the fiber tree and how hooks values are stored in memory. The Talk also delves into the conditional use of useContext and how it differs from useState. It explores the process of updating context values and optimizing context rendering. The role of the provider in managing context values and rendering is emphasized.
Efficient State Management With Hookstate
React Advanced 2021React Advanced 2021
10 min
Efficient State Management With Hookstate
This Talk introduces hook state as a flexible and simple state management solution for React. It demonstrates how hook state can be used for global state management, as well as for managing state within individual components. The speaker highlights the ease of using hook state for tasks such as adding, updating, and removing tasks. The conclusion encourages further exploration of hook state for efficient state management in React applications.
Don't Forget React Memo
React Summit 2022React Summit 2022
7 min
Don't Forget React Memo
The Talk covers topics such as React memo compiler, use memo and use callback, building custom hooks, and the benefits of using use ref. It also explores the similarities between use memo and use ref, and the use of React Memo for preventing re-renders and optimizing expensive calculations. The speaker also shares personal information and contact details.
We Don’t Know How React State Hooks Work
React Summit Remote Edition 2021React Summit Remote Edition 2021
7 min
We Don’t Know How React State Hooks Work
This Talk provides an introduction to React Staytools, explaining how to use the state and setState function to update a counter. It also delves into the inner workings of React rendering, discussing the update queue and re-rendering conditions. The Talk concludes by mentioning the different modes of updating and triggering re-renders in React, and encourages further exploration of the source code and discussion in Discord.
We Don’t Know How React State Hooks Work
React Advanced 2021React Advanced 2021
28 min
We Don’t Know How React State Hooks Work
This talk explores how useState works under the hood and why it's important to understand. It addresses the common confusion around the callback to setState and provides insights gained from exploring React hooks source code. Knowing how useState works is important for learning patterns, debugging, and gaining confidence in our code. React manages the current value of hooks in a linked list and performs updates sequentially. React optimizes rendering by caching computations and performing shallow renders when the state doesn't change.
The Art of Ignoring Best Practices for React Performance
React Summit 2024React Summit 2024
19 min
The Art of Ignoring Best Practices for React Performance
This Talk introduces the concept of being a 'React bad boy' by ignoring best practices and optimizing React rendering. It explains how to avoid unnecessary rerenders using React.memo and React DevTools. It also covers advanced techniques like isolating state changes and lazy loading hooks. The Talk explores reducing component rerenders using Svelte stores and optimizing with swap stores in Redux. These techniques improve React performance without the need for major refactors or rewrites.

Workshops on related topic

React Hooks Tips Only the Pros Know
React Summit Remote Edition 2021React Summit Remote Edition 2021
177 min
React Hooks Tips Only the Pros Know
Top Content
Featured Workshop
Maurice de Beijer
Maurice de Beijer
The addition of the hooks API to React was quite a major change. Before hooks most components had to be class based. Now, with hooks, these are often much simpler functional components. Hooks can be really simple to use. Almost deceptively simple. Because there are still plenty of ways you can mess up with hooks. And it often turns out there are many ways where you can improve your components a better understanding of how each React hook can be used.You will learn all about the pros and cons of the various hooks. You will learn when to use useState() versus useReducer(). We will look at using useContext() efficiently. You will see when to use useLayoutEffect() and when useEffect() is better.
State Management in React with Context and Hooks
React Summit Remote Edition 2021React Summit Remote Edition 2021
71 min
State Management in React with Context and Hooks
Workshop
Roy Derks
Roy Derks
A lot has changed in the world of state management in React the last few years. Where Redux used to be the main library for this, the introduction of the React Context and Hook APIs has shaken things up. No longer do you need external libraries to handle both component and global state in your applications. In this workshop you'll learn the different approaches to state management in the post-Redux era of React, all based on Hooks! And as a bonus, we'll explore two upcoming state management libraries in the React ecosystem.
Evolution of Form Management in React
React Summit US 2024React Summit US 2024
72 min
Evolution of Form Management in React
Workshop
Adrian Hajdin
Adrian Hajdin
Learn how to handle forms in React using the latest features, such as startTransition, useTransition, useOptimistic, and useActionState, with and without React 19 server actions, alongside proper validation, error handling, and best practices.The workshop will begin by demonstrating traditional form handling using useState and useEffect for client-side rendering. Gradually, we'll transition to using the latest React 19 features, including server-side forms and the newest hooks for managing form states and errors. By the end of the workshop, participants will understand how to create robust forms with proper validation and error handling.Learning GoalsLatest React 19 Hooks — useTransition, useFormStatus, useOptimistic, useActionState, useDeferredValueServer ActionsRevalidationsServer-side ValidationError handlingSecurity practices