Asia/Kolkata
BlogAugust 15, 2024

React fiber object

Arun Et
What exactly is a fiber object? Each instance of a component is internally represented in React as a ‘Object’, and these Objects have a lot of properties that are used by React to keep track of things like state and props. It stores crucial information about the component it represents. A react component structured as below will be represented as object, as shown below
Fiber object representation of IndexRoute component
This object is used internally by react to represent a element or node within the component tree. These properties work together to manage rendering, updates, and debugging. Core ones like child/sibling/return form the tree structure, while effects and expiration handle scheduling.
  1. $$typeof: This property is used to identify and differentiate React elements from regular JSON.
Read the original pull request to understand the rationale why $$typeof should exist: According to "Sebastian Markbåge" who made this change, the primary motivation is to prevent XSS attacks in react_v0.14. Since Symbols cannot be stored in JSON as Symbols are non-string, non-serializable primitives in JavaScript. User input JSON, containing $$typeof with a symbol is not a possibility. React will check element.$$typeof , and will refuse to process the element if it’s missing or invalid. These are the possible values for $$typeof in react: The fallback solution is a plain well-known number. var REACT_ELEMENT_TYPE = 0xeac7;
Why this number specifically? 0xeac7 kinda looks like “React”. - Dan Abramov

  1. key: Used during reconciliation to determine if a fiber can be reused when components are reordered
  2. type: Describes what kind of component this represents - for composite components it's the function/class, for DOM elements it's a string like "div"
  3. tag: Numeric identifier indicating the fiber type (FunctionComponent, ClassComponent, HostComponent, etc.)
below are the possible Numeric identifiers for tag property in react
Share this post: