ReactNode, ReactElement, Component, div: which live only in memory, and which becomes DOM

2026/04/21
reactinternalstypes

Writing React means meeting four names every day: ReactNode, ReactElement, Component, and HTML tag names like div. Early on it is easy to treat them as the same thing, since they all seem to be a piece of the screen. Yet returning <Comp /> renders, while returning Comp shows nothing; assigning a string to a variable typed ReactElement is a TypeScript error, while assigning it to ReactNode is fine.

So what is each of these names? Which ones exist only in JavaScript memory, and which one ends up as a DOM node in the browser?

render and commit

Every time React updates the screen, it works in two steps:

  1. render: React calls your component functions and works out what the screen should become. This step only handles JavaScript objects; the DOM on the page does not change.
  2. commit: React writes the changes that render worked out into the DOM on the page.

After commit, the browser still has to compute styles, lay out, and paint pixels. Those steps are in from setState to pixels.

What each name is

NameWhat it isWhere it exists
ReactNodeA TypeScript type, the widest one: any value React can renderOnly during type checking; gone once compiled to JavaScript
ReactElementA plain object made by JSX or createElement; main fields are type, props, keyJavaScript memory
ComponentA function or class that takes props and returns what to renderA function in JavaScript memory
divA string, the name of an HTML tagThe string is in JavaScript memory; React creates an HTMLDivElement for it during render and puts it on the page at commit

Of the four names, only div ends up matched to a DOM element on the page. Strings and numbers are ReactNodes too, though, and they become Text nodes. After <b>{42}</b> commits, the <b> on the page holds one Text node whose content is "42". null and false produce no DOM.

How the four relate

ReactNode contains ReactElement

ReactNode is the widest type. Any value React can render counts, and ReactElement is just one kind:

<div />                          // ReactElement
<>hi</>                          // also a ReactElement, type is React.Fragment
'hello'                          // string
42                               // number
null
false
[<a key="a" />, <b key="b" />]   // array

Checked with TypeScript 5.9.3 and @types/react 19.3.0, every line above is assignable to ReactNode. <>hi</> is also assignable to ReactElement, because JSX compiles it to jsx(Fragment, { children: 'hi' }), which produces an element whose type is React.Fragment.

Component and 'div' sit in the same field

A ReactElement produced by the React 19.3.1 production build looks like this:

{ $$typeof: Symbol(react.transitional.element), type, key, ref, props }

$$typeof is the marker React uses to confirm "this is an element"; React.isValidElement checks it.

The type field can hold a string such as 'div', which makes the element a host component, or it can hold a Component, meaning a function or a class. The two kinds of value share one field and neither contains the other:

<div>hi</div>        // type: 'div'      string, host component
<Button>hi</Button>  // type: Button     function, your own component

During render, React looks at type to decide what to do:

  • String: create a DOM node for it, and put it on the page at commit.
  • Function or class: call it, and keep going with whatever it returns.

Component produces ReactElements

When you write <Button label="OK" />, Button has not been called yet. The line only produces an element with type: Button. React calls Button when render reaches that element. What it returns is usually a ReactElement, but it can also be a string or null; in any case it is a ReactNode.

function Button({ label }) {
  return <span>{label}</span>   // returns a ReactElement
}

There is no Button on the page. Only the <span> it returns becomes a <span> node on the page, at commit.

From <Greeting /> to HTMLDivElement

function Greeting({ name }) {
  return <div>Hello, {name}</div>
}
 
const tree = <Greeting name="Jialin" />

tree is a ReactElement, and its type field holds the Greeting function itself:

{
  $$typeof: Symbol(react.transitional.element),
  type: Greeting,
  key: null,
  ref: null,
  props: { name: 'Jialin' }
}

At this point Greeting has not been called.

During render, React creates a fiber for each element. A fiber is React's own record object: what kind of component this is, what its props are, where its state lives, which children it has, which DOM node it maps to. No field on the fiber points at the element object; React copies only the element's type, key and props onto the fiber. In React 19 ref lives inside props, so it is copied too. The code is createFiberFromElement in ReactFiber.js. Elements are made fresh every render, while fibers stay for the next render.

The fiber for Greeting is created first. React sees that type is a function, calls it with the props, and gets another element:

{
  $$typeof: Symbol(react.transitional.element),
  type: 'div',
  key: null,
  ref: null,
  props: { children: ['Hello, ', 'Jialin'] }
}

This time type is the string 'div', and React creates a host component fiber for it. The two strings in children get a fiber each as well. Rendering <Greeting name="Jialin" /> with React 19.3.1 in Chrome 156 and then walking every fiber down from the root prints:

HostRoot
  FunctionComponent  Greeting    stateNode = null
    HostComponent    div         stateNode = HTMLDivElement
      HostText       "Hello, "   stateNode = Text
      HostText       "Jialin"    stateNode = Text

The full fiber definition lives in ReactInternalTypes.js. The div fiber, with most fields removed, looks roughly like this:

{
  tag: HostComponent,
  type: 'div',                    // same as the element's type
  stateNode: HTMLDivElement,      // DOM node created during render
  child: Fiber,                   // first child, here the "Hello, " fiber
  sibling: null,                  // next sibling
  return: Fiber,                  // parent, here the Greeting fiber
  alternate: Fiber | null,        // matching fiber in the other fiber tree, next section
  memoizedProps: { children: ['Hello, ', 'Jialin'] },
  memoizedState: null,            // a function component's fiber keeps its hook list here
  lanes: 0,                       // pending updates on this fiber, and their priorities
  flags: 0,                       // what commit must do: Placement, Update, ChildDeletion, etc.
}

When the DOM node is created, and when it enters the page

Wrap document.createElement and appendChild with logging, then mount an App with the React 19.3.1 production build. App has two children: A renders <section><p>a</p></section>, and B renders <div>b</div>. The logged order is:

  1. render App
  2. render A
  3. document.createElement('p')
  4. document.createElement('section')
  5. <p> appended under <section>; <section> is not on the page yet
  6. render B
  7. document.createElement('div')
  8. <section> appended under #root; only now is it on the page
  9. <div> appended under #root
  10. useLayoutEffect

<section> and <p> exist before B renders, which means they were created during render. As React walks the fibers, it passes each fiber twice: on the way down it calls the component, and on the way back up it finishes the fiber, a step called completeWork. A host component fiber creates its DOM node in completeWork and appends its children's DOM nodes to it; none of this is on the page yet. In ReactFiberCompleteWork.js, the HostComponent branch calls createInstance and appendAllChildren. At commit, React puts the assembled DOM into #root. The way down and the way back up are covered in Inside React's work loop.

The whole path, in order:

  1. Greeting is a function in your source code; it is always there.
  2. JSX produces the element { type: Greeting }; the next render produces a new element.
  3. React creates a fiber for it. Hook values live on this fiber, which stays for the next render.
  4. React calls Greeting and gets the element { type: 'div' }. Once React copies its type, key and props onto the fiber, no fiber references it.
  5. React creates a fiber for it, which also stays for the next render.
  6. completeWork creates an HTMLDivElement for that fiber and stores it in stateNode; it is not on the page yet.
  7. Commit puts the HTMLDivElement on the page.

Why each fiber has two copies

React keeps two fiber trees at the same time: current is the version on screen, and workInProgress is the version this render is building. The fibers on both sides for the same <div> point their stateNode at the same HTMLDivElement: when createWorkInProgress builds a workInProgress fiber, it copies stateNode from current.

So when React changes things on workInProgress, does it change the DOM on screen?

No. stateNode is only a reference to the DOM node. Changing the DOM takes calls like setAttribute, appendChild, removeChild, and React only makes them in commit's mutation step, in commitMutationEffectsOnFiber in ReactFiberCommitWork.js. What render changes are the fiber's own fields:

wipFiber.memoizedProps = { children: 'new text' }  // the fiber's own field
wipFiber.flags |= Update                           // the fiber's own field
wipFiber.child = newChildFiber                     // a pointer between fibers

The only DOM render creates is for nodes added in this update, like the <section> in the previous section, and those are not attached to the page when they are created.

React does not prepare two copies of every fiber, though. At mount each fiber has one copy. Only when the first update comes and render reaches it does React create a second copy, and from then on the two take turns as current. So "this component's fiber" is not one fixed object; it switches to the other copy every render. The DOM node behind <div>, on the other hand, is the same one throughout.

If a component is wrapped in React.memo and its props did not change, React skips its whole subtree. A fiber in that subtree stays a single copy for as long as render never reaches it. Because there is only one copy, its alternate is null, and the current and workInProgress trees use the same fiber object. The comment in createWorkInProgress says the same: the second fiber is created only when needed, "to avoid allocating extra objects for things that are never updated". As long as the component's type and key stay the same, React keeps alternating between these two objects and never creates a third.

What commit swaps

Three things in commit, in this order, involve the two fiber trees:

  1. mutation: change the real DOM, such as setAttribute, appendChild, removeChild. Every change the user will see happens here.
  2. swap current: root.current = finishedWork; workInProgress becomes current.
  3. layout: run useLayoutEffect and componentDidMount.

There are two copies of each fiber but only one DOM, so mutation has no second DOM to prepare and swap in. It changes the nodes on the page directly, for example changing an attribute, or adding and removing a few nodes. By the time current is swapped, the DOM is already updated, so this line changes nothing on screen. What it affects is the next render: React uses the version just finished as current and compares its props with the new ones, and the old version swapped out becomes the next workInProgress.

The line sits at the end of flushMutationEffects in ReactFiberWorkLoop.js, which commitRoot calls:

  // The work-in-progress tree is now the current tree. This must come after
  // the mutation phase, so that the previous tree is still current during
  // componentWillUnmount, but before the layout phase, so that the finished
  // work is current during componentDidMount/Update.
  root.current = finishedWork;
  pendingEffectsStatus = PENDING_LAYOUT_PHASE;

finishedWork is the workInProgress version. The line runs after mutation and before layout, so componentWillUnmount still sees the old version as current, while useLayoutEffect and componentDidMount already see the new one.

alternate on mount, update, delete

CaseWhere this fiber isalternate
mountonly in workInProgressnull
update, and this render reached itone copy each in current and workInProgressthe two point at each other
update, and its whole subtree was skippedcurrent and workInProgress share one objectstays null if it was never reached
deleteonly in currentReact builds no workInProgress fiber for it

React does not mark a deletion by setting alternate to null. A node being removed gets no workInProgress fiber; React puts the old fiber into the parent's deletions array and adds the ChildDeletion flag to the parent. Commit reads that array and calls removeChild. The code is deleteChild in ReactChildFiber.js; it changes only the parent's deletions and flags, and nothing touches the removed child's alternate.

Where useState keeps its value

A function component is just a function. It runs, returns, and its local variables are gone. Write let count = 0 inside a component and it goes back to 0 every render. So how does a useState value survive until the next render?

It lives on the component's fiber, in the memoizedState field. That field points to a linked list, with one node for every call to useState, useRef, useEffect. For a component that calls useState, useRef, useEffect in that order, fiber.memoizedState points to the first node (the useState one), its next points to the useRef node, and the one after that is the useEffect node.

As the previous section showed, a component's fiber has two copies that take turns. On each render, updateWorkInProgressHook in ReactFiberHooks.js copies the hook nodes from the current fiber to the workInProgress fiber one by one, in order, so the values carry over. Each time render reaches a useState, React moves to the next node in the list and hands back what is stored there.

How does React know which node belongs to which useState? It does not know your variable names, so it cannot tell which useState is name and which is age. It can only count: the first call gets the first node, the second call gets the second, and so on.

The hook node has no place for a name either. React creates hook nodes in mountWorkInProgressHook in ReactFiberHooks.js:

const hook = {
  memoizedState: null,
  baseState: null,
  baseQueue: null,
  queue: null,
  next: null,
};

No name, no key, no id; the only link from one hook to the next is next.

So the order of hook calls has to be the same on every render. Try putting a hook inside an if:

function Profile({ show }) {
  if (show) {
    const [name] = useState('Ann')   // sometimes called, sometimes skipped
  }
  const [age] = useState(20)
}

First render, show is true. Two calls, two nodes:

CallNode it getsValue
1st (name)node 1'Ann'
2nd (age)node 220

Next render, show is false, and the if skips the first call. One call is left, and React still counts from the top:

CallNode it getsValue
1st (age)node 1'Ann'

age gets the first node and reads name's value. Every hook after the skipped one moves up a position and reads the wrong value. React expected two hooks and saw one, so it throws. Running this with the React 19.3.1 development build, age on the second render is indeed 'Ann', followed by "Rendered fewer hooks than expected. This may be caused by an accidental early return statement." That is why the Rules of Hooks put hooks at the top level of a component: not inside if or for, and not after an early return.

A few more questions

Why does <MyComponent /> render, but lowercase <myComponent /> does not?

The JSX compiler looks at the first letter to decide what goes into type: uppercase means a variable, lowercase means a string. Compiled with esbuild 0.25.10:

<div />          →  createElement("div", null)          // lowercase: a string
<MyComponent />  →  createElement(MyComponent, null)    // uppercase: a variable
<myComponent />  →  createElement("myComponent", null)  // lowercase: still a string

<myComponent /> looks like a component, but its first letter is lowercase, so the compiler emits the string "myComponent". React gets type: "myComponent", treats it as an HTML tag, and creates a <mycomponent>. The function named myComponent is never called.

As JSX In Depth also notes, casing is the JSX compiler's rule; React only receives the type the compiler already decided.

Why can a component return null but not a Component?

What a component returns has to be a ReactNode. null is a ReactNode, meaning "render nothing here". A Component is a function, and a function is not a ReactNode. You need <Comp />, not just Comp.

In React 19.3.1, return Comp puts nothing on screen. The development build logs "Functions are not valid as a React child. This may happen if you return Comp instead of from render. Or maybe you meant to call this function rather than return it." The production build logs nothing. In TypeScript, assigning a function to a variable typed ReactNode is an error.

Why does changing a list item's key reset its state?

During render, React matches new elements to existing fibers by key:

  • Same key and type: reuse the fiber; its memoizedState and DOM node stay.
  • Different key: drop the old fiber and create a new one with empty state.

Using the array index as the key causes trouble: insert a row at the top, every index shifts by one, and React pairs the wrong fiber with the wrong row. Below, every row has a useState('note for ' + label), and A is inserted in front of B and C:

KeyBeforeAfter inserting A at the top
indexB / note for B, C / note for CA / note for B, B / note for C, C / note for C
each row's own idB / note for B, C / note for CA / note for A, B / note for B, C / note for C

With index keys, A got B's old state, B got C's, and C is a newly created fiber.

Summary

  1. JSX produces a ReactElement, whose type is a string or a Component.
  2. During render, React creates a fiber for each element, or reuses the one from last time. If type is a Component, React calls it and gets more elements.
  3. React walks the fibers one at a time through child, sibling and return, without recursive calls.
  4. A fiber whose type is a string creates its DOM node in completeWork and attaches its children; it is not on the page yet.
  5. Commit puts those DOM nodes on the page, then swaps root.current to the new version.

Environment

ItemVersion
React, react-dom19.3.1, bundled with esbuild 0.25.10, production and development builds
BrowserGoogle Chrome 156.0.8078.79, headless, Playwright 1.64.1
TypeScript5.9.3, @types/react 19.3.0
Node.js22.22.3
OSmacOS (Darwin 24.6.0)
Source comparedreact/react v19.3.1 tag

Related: from setState to pixels and Inside React's work loop.