# Preact Signals & Bypassing the VDOM

> Achieve true fine-grained reactivity by updating the DOM without re-rendering components.

Subject: State Management | Lesson 21 of 22 | 7 min read
Interactive lesson: https://codewithanimation.in/state-management/signals-bypassing-vdom
Previous: [Derived & Async Atoms](https://codewithanimation.in/state-management/jotai-derived-and-async-atoms.md) | Next: [Signal Computed & Effects](https://codewithanimation.in/state-management/signals-computed-and-effects.md)

## What is a Signal?

A Signal is a reactive state container that holds a `.value`. When the value changes, the signal automatically notifies anything that is currently subscribing to it.

Unlike React `useState`, Signals are framework-agnostic objects that can live inside or outside of component bodies.

## Bypassing the Virtual DOM

In standard React, calling a state setter forces the entire component function to re-execute, generating a new Virtual DOM tree that React must diff against the previous one.

Signals offer true fine-grained reactivity. When you pass a signal directly into JSX (e.g., `<div>{countSignal}</div>`), the library intercepts it and updates the text node in the actual DOM directly, completely bypassing the parent component's render function and the VDOM diffing process.

## Reading .value vs Passing the Object

If you read `countSignal.value` inside your component body, you force the component to subscribe to the signal and it will re-render normally.

To bypass the re-render, you must pass the signal object reference *itself* into the JSX: `{countSignal}`. The package `@preact/signals-react` patches React's JSX runtime to handle this automatically.

## Common mistake: The useMemo Boilerplate

Historically, if a frequently changing value (like a scroll position or a fast counter) lived high up in the component tree, it would ruin performance by re-rendering every child component.

Engineers had to defensively wrap everything in `React.memo` or `useMemo`. Signals solve this at the root by skipping the VDOM entirely.

## Tip: Updating Signals

You update a signal by mutating its `.value` property directly: `count.value++`. Because the value is intercepted by a setter under the hood, this mutation is safe and instantly reactive.

## Try it: Interactive Lab: The VDOM Bypass Proof

Click the button to increment the Signal. Watch closely: the text on the screen updates, but the component's render count stays permanently frozen at 1!

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/state-management/signals-bypassing-vdom

## Check yourself

### Question 1

How do you ensure a React component DOES NOT re-render when a signal updates, but the text on screen still changes?

- A. Read `signal.value` inside a `useMemo` block.
- B. Pass the signal object directly into the JSX: `<div>{signal}</div>`.
- C. Wrap the component in `React.memo`.

Correct answer: B

By passing the signal object directly to JSX, the component never reads `.value` during its execution, so it never subscribes. The JSX runtime handles the DOM text update directly.

- Why not A: If you read `.value` anywhere in the component render phase, it subscribes the component to updates.
- Why not C: React.memo prevents renders from parent prop changes, but reading `.value` would still trigger an internal state update.

## Remember this

- A Signal wraps a reactive `.value`.
- Updating a Signal's value does not inherently trigger a React component re-render.
- Reading `.value` inside a component body subscribes the component to re-renders.
- Passing the signal object `{signal}` directly into JSX bypasses the Virtual DOM entirely.
