Skip to content
Tutorials Center
My learning

Topics

Lesson 4 of 39 ยท Getting Started

SolidJS vs React: Mental Model Differences

Coming from React? Map useState, useEffect and useMemo to Solid, learn why props must not be destructured, and avoid the classic first-week mistakes.

Solid's JSX looks so much like React's that the differences are easy to miss, and that is where bugs come from. This lesson is a translation guide. If you have never used React, read it anyway: it states the rules you will rely on all course long.

One rule changes everything

In React, a component function runs again every time state changes, so values in the function body are always fresh. In Solid the function runs once, so the body is setup and the places that must stay current are reactive expressions.

From that single difference come almost all the others.

The mapping table

React Solid Notes
useState createSignal Getter is a function: count()
useEffect createEffect No dependency array; tracked automatically
useMemo createMemo Returns an accessor; also a cached function
useRef a plain variable + ref No re-render, so no special hook
useContext useContext Same idea, see context in a later chapter
useReducer createStore Fine-grained nested state
React.memo not needed Components do not re-run
key prop <For> / <Index> The list component tracks items
{cond && <X/>} <Show when={cond()}> Works as an expression too, but Show is preferred
useEffect(() => {...}, []) onMount Runs once after first render
cleanup return value onCleanup Call it, instead of returning a function
className class (or className) Real HTML names are used
onChange on inputs onInput Use the native event name

Signals are not state variables

A React state variable holds a value. A Solid signal is a function you call to read, and another to write:

JSX
// React
const [count, setCount] = useState(0);
return <p>{count}</p>;

// Solid
const [count, setCount] = createSignal(0);
return <p>{count()}</p>;

Forgetting the parentheses is the most common mistake in the first week. would insert the function itself (and Solid would call it for you in a JSX spot, which hides the mistake), but count + 1 would produce text like function count()...1.

Do not destructure props

In React you often write function Hello({ name }). In Solid, props is a reactive object: reading props.name inside a tracked spot subscribes to it. Destructuring reads it immediately, once, during setup, so later updates are lost.

Destructured props go stale

Press Swap name. The second line follows the signal; the first one is stuck on "Ada". The parent changed the value, but Broken copied it out of the reactive object when it ran its setup. Props and Reactivity shows the safe ways to split and rename props.

Solid's compiler also warns about destructuring in many editors through the ESLint plugin eslint-plugin-solid. Install it in real projects: it catches this class of bug automatically.

Signals live anywhere

React hooks must be called in components and custom hooks, always in the same order. A Solid signal is just a function pair, so you can create one in a module and share it between any components:

A signal outside any component

Neither component knows about the other, and there is no provider, no prop drilling and no re-rendering of a parent. (For per-user or per-tree state you would use context, which has its own lesson later.)

Behaviors that surprise React developers

  • No stale closures. Because you read signals by calling them, count() always returns the current value, even inside a setTimeout created long ago.
  • No dependency arrays. createEffect tracks what it reads. Forgetting a dependency is impossible; reading too much is the thing to watch.
  • Effects do not run during setup like useEffect. They run after the component's DOM is created.
  • Conditional returns are not reactive. An if that returns different JSX from the component body runs once. Use <Show> or <Switch> for branches that must change over time.
  • No fragments needed for siblings in many cases, but multiple root elements still work with <>...</>.
  • Events are native. onClick is attached through delegation and gets the real browser event, not a synthetic one.
JSX
// Looks fine in React, silently wrong in Solid
function Status(props) {
  if (props.loading) return <p>Loading...</p>; // checked once!
  return <p>Done</p>;
}

// Right: let a control-flow component re-evaluate
function Status(props) {
  return (
    <Show when={!props.loading} fallback={<p>Loading...</p>}>
      <p>Done</p>
    </Show>
  );
}

When to pick which

React has the largest ecosystem, the most hiring demand and mature tools like React Native. Solid has the leaner runtime, less ceremony (no memo, no callback hooks, no dependency arrays), and predictable performance on large reactive screens. Many teams choose Solid for new, performance-sensitive front ends and keep React where the ecosystem matters most.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which Solid primitive replaces useState?

    createSignal returns a getter and a setter. useReducer maps to createStore, and useMemo to createMemo.
  2. 2. Why does const { name } = props break updates?

    Reactivity lives in reading props.name inside a tracked expression. Destructuring copies the current value and loses the link.
  3. 3. Where can you create a signal?

    Signals are plain function pairs, not hooks, so there is no rule about call order or location.
  4. 4. An if statement in a component body returns <p>Loading</p> when props.loading is true. What is the problem?

    The body runs once. Use <Show> or <Switch> so the condition is re-evaluated reactively.
  5. 5. What replaces the cleanup function returned from useEffect?

    Call onCleanup(fn) inside the effect or component. It runs when the owner is disposed or the effect re-runs.

Summary

  • Solid components run once; only reactive expressions re-run.
  • createSignal, createEffect, createMemo and createStore replace the usual hooks, without dependency arrays.
  • Read signals by calling them, and never destructure props.
  • Signals work at module scope, which makes shared state simple.
  • Use <Show>, <Switch> and <For> where React code would use &&, ternaries and map with keys.

Next: Creating Signals