From React
Components, props, JSX, events, context, and refs all carry over from React. The main change is how state changes reach the DOM. This page maps React patterns to Solid one by one. Thinking in Solid shows the same shift inside one feature built end to end.
Components run once
A React component runs again every time its state changes. A Solid component runs once, when it mounts. After that, a signal updates only the JSX expressions and computations that read it.
// Reactfunction Counter() { const [count, setCount] = useState(0); return <button onClick={() => setCount(count + 1)}>{count}</button>;}
// Solidfunction Counter() { const [count, setCount] = createSignal(0); return <button onClick={() => setCount(count() + 1)}>{count()}</button>;}count is an accessor: a function that returns the current value.
Calling count() inside JSX subscribes that expression to the signal.
A read in the component body runs once and never updates, because the body is not tracked.
Reactivity explains tracking in detail.
Hooks map
| React | Solid |
|---|---|
useState | createSignal |
useState with an object, useReducer | createStore, see Objects and reducers |
useMemo | A plain function, or createMemo for expensive or shared work |
useEffect, useLayoutEffect | createEffect, see Effects |
useEffect(fn, []) | onSettled |
useContext | createContext and useContext |
useRef | A ref callback, see Refs |
useSyncExternalStore | A signal written from the subscription, see External stores |
useTransition, useDeferredValue | isPending, latest, createDeferred |
useOptimistic | action with an optimistic store, see Mutations |
useCallback, React.memo | Not needed, see What goes away |
| A custom hook | A custom primitive, see Custom hooks |
Solid primitives are plain function calls. There are no hook rules: you can call them conditionally or in a loop, as long as a component or other owner is running.
Objects and reducers
React updates an object by building a new one. A Solid store gives you a read-only reactive object and a setter that changes a draft in place:
const [state, setState] = createStore({ todos: [] as Todo[] });
function toggle(id: string) { setState((draft) => { const todo = draft.todos.find((item) => item.id === id); if (todo) todo.done = !todo.done; });}A function such as toggle replaces a reducer case and its dispatch call.
Toggling one todo updates only the JSX that reads that todo's done.
The reducer habit of building a new array still compiles:
// Avoid: a new array replaces the one every reader depends onsetState((draft) => { draft.todos = draft.todos.map((todo) => todo.id === id ? { ...todo, done: true } : todo );});Every reader of state.todos runs again, and For recreates the row instead of updating it.
Change the item in place, as toggle does.
A write outside the setter, such as state.todos.push(todo), is ignored, and development reports [STORE_WRITE_OUTSIDE_SETTER].
Stores covers projections, reconciliation, and optimistic stores.
Derived values
A value calculated from other state stays a function:
const fullName = () => `${firstName()} ${lastName()}`;Use createMemo when the work is expensive or several places read the result.
Do not copy derived values into a second signal with an effect.
To follow a prop until the user edits it, pass a function to createSignal.
This replaces React's pattern of storing the previous prop and comparing it during render:
function NameField(props: { name: string }) { const [draft, setDraft] = createSignal(() => props.name);
return ( <input value={draft()} onInput={(event) => setDraft(event.currentTarget.value)} /> );}setDraft sets a local value, and a new props.name replaces it.
Avoid unnecessary effects covers more cases.
Effects
A React effect lists its dependencies in an array. A Solid effect has two functions: a tracked compute function that reads the dependencies, and an effect function that does the work.
// ReactuseEffect(() => { const connection = connect(roomId); return () => connection.close();}, [roomId]);
// SolidcreateEffect( () => props.roomId, (roomId) => { const connection = connect(roomId); return () => connection.close(); });Reads inside the effect function are not tracked. Many React effects do not need an effect in Solid: calculate values with a function or memo, and start work from the event handler that caused it.
For setup that runs once after mount, use onSettled.
The function it returns runs when the component is removed:
onSettled(() => { const id = setInterval(() => setNow(Date.now()), 1000); return () => clearInterval(id);});Both onSettled and effect functions run after the DOM is updated, so there is no separate layout effect.
React skips an effect when no dependency changed. Solid re-runs the effect function whenever a value the compute function read changes, even if the compute function returns the same result. To skip equal results, put the comparison in a memo and pass the memo as the compute function:
const large = createMemo(() => count() > 100);createEffect(large, (isLarge) => report(isLarge));Props
Solid props can be getters, so destructuring them reads each value once and loses updates.
Keep the props object and read props.name where you use it:
function Greeting(props: { name: string }) { return <p>Hello, {props.name}</p>;}For defaults and rest props, use merge and omit:
function Button(props: ButtonProps) { const merged = merge({ variant: "primary" } as const, props); const rest = omit(merged, "variant", "children");
return ( <button data-variant={merged.variant} {...rest}> {merged.children} </button> );}Unlike a React default parameter, merge treats an explicit undefined as a value, so variant={undefined} does not fall back to "primary".
Events, attributes, and styles
- Handlers receive native DOM events.
onInputfires on each keystroke, andonChangeuses the native change event. - Use
classinstead ofclassName.classalso accepts objects and arrays. - Style objects use CSS property names such as
"background-color", and numbers do not getpxadded. - Event handlers are not tracked, so they can read signals without subscribing.
Conditions and lists
Ternaries and && work in JSX and update when their condition changes.
Use Show when you want a fallback or a narrowed value.
map renders, but it recreates every row each time the list changes.
Use For for lists that change.
Its keyed prop plays the role of React's key:
<For each={todos()} keyed={(todo) => todo.id}> {(todo) => <TodoRow todo={todo()} />}</For>Context
The context object is also its provider component:
const ThemeContext = createContext<ThemeContextValue>();
<ThemeContext value={{ theme, setTheme }}>{props.children}</ThemeContext>;Pass signals or stores through context to share reactive state. Avoid module-level signals for shared state, because on the server one module is shared by every request.
Refs
A ref callback receives the element:
let input!: HTMLInputElement;
<input ref={(element) => (input = element)} />;Components receive a ref as props.ref, so there is no forwardRef.
To use the element locally and pass it on, give ref an array: ref={[props.ref, (el) => (input = el)]}.
See Refs and directives.
Custom hooks
A custom hook becomes a function, usually named createX, that takes and returns accessors:
function createDebounced(value: Accessor<string>, ms: number) { const [debounced, setDebounced] = createSignal(untrack(value));
createEffect(value, (next) => { const id = setTimeout(() => setDebounced(next), ms); return () => clearTimeout(id); });
return debounced;}Return debounced, not debounced(): a plain value never updates.
Custom primitives covers the pattern.
External stores
Instead of useSyncExternalStore, write a signal from the subscription:
function createOnlineStatus() { const [online, setOnline] = createSignal(true);
onSettled(() => { const update = () => setOnline(navigator.onLine); update(); return subscribe(update); });
return online;}onSettled does not run on the server, and the starting value matches what the server rendered.
When the subscription depends on a prop, subscribe in an effect instead, as Integrate non-Solid code shows.
Async data
An async memo returns a value, not a promise.
Loading plays the role of Suspense, and Errored plays the role of an error boundary:
function Page(props: { id: string }) { const user = createMemo(() => fetchUser(props.id));
return ( <Errored fallback={(error) => <p>{String(error())}</p>}> <Loading fallback={<p>Loading...</p>}> <h2>{user().name}</h2> </Loading> </Errored> );}Only the expressions that read user() wait.
Nested components still set up and start their own requests, so nesting does not create a request waterfall.
Reveal controls the order in which sibling Loading boundaries appear.
Pending updates
There is no startTransition.
When a write leads to new async work, Solid keeps the current content on screen until the new data is ready.
Use isPending to show that an update is in progress, and latest to read the new value early:
const [tab, setTab] = createSignal("posts");const content = createMemo(() => fetchTab(tab()));
<button disabled={latest(tab) === "photos"} onClick={() => setTab("photos")}> Photos</button>;<Loading fallback={<Spinner />}> <div class={{ dimmed: isPending(() => content()) }}>{content()}</div></Loading>;Until the photos arrive, tab() still returns "posts".
For useDeferredValue, use createDeferred, which lets the result lag without holding the input.
Async reactivity covers both.
Mutations
useOptimistic becomes an action that writes to an optimistic store:
const [todos, setTodos] = createOptimisticStore(() => api.listTodos(), []);
const addTodo = action(function* (text: string) { setTodos((list) => { list.push({ id: crypto.randomUUID(), text, pending: true }); }); yield api.addTodo(text); refresh(todos);});The row appears at once.
When the action finishes, the optimistic row is replaced by the refreshed list.
If the request fails, the row is removed without rollback code.
Use yield, not await: code after a plain await runs outside the action.
With Solid Router, see Data loading and mutations.
What goes away
React.memo: a parent update does not run the child again.useCallback: functions in the component body are created once.- Dependency arrays: the compute function tracks what it reads.
- Stale closures: a handler that calls
count()reads the current value. - Hook rules and Strict Mode double runs.
Habits that still compile
These React habits compile in Solid and then misbehave.
Codes marked "attribution" appear once attribution.enable() from solid-js/attribution is running, as Debugging reactivity describes.
| React habit | What happens in Solid | What reports it |
|---|---|---|
| Destructuring props, or reading a signal in the body | The value never updates | STRICT_READ_UNTRACKED |
An early return that depends on props | The component stays on its first branch | STRICT_READ_UNTRACKED |
Passing the accessor: value={count} | The child receives a function | A TypeScript error |
| Building new objects for list items on each update | For recreates every row and loses focus | UNSTABLE_LIST_IDENTITY (attribution) |
| Copying a derived value into state from an effect | The copy is one update behind | EFFECT_RELAY_TEAR (attribution) |
| Setting state during render | Throws | REACTIVE_WRITE_IN_OWNED_SCOPE |
useEffect(fn) translated to createEffect(fn) | Throws | MISSING_EFFECT_FN |
| Reading a signal inside the effect function | The effect does not re-run when it changes | STRICT_READ_UNTRACKED |
Reading a signal after await in an async memo | The memo does not re-run when it changes | UNTRACKED_READ_AFTER_AWAIT (V8 engines) |
createContext<T | undefined>(undefined) | useContext throws without a provider | ContextNotFoundError; use null as the default |
onClick={ready() ? save : wait} | The first handler stays bound | STRICT_READ_UNTRACKED; decide inside one handler |
A lowercase onclick | The handler is never attached | LOWERCASE_EVENT_ATTRIBUTE |
value={props.name} onChange={commit} with no draft signal | Another attribute change erases the typed text | UNCOMMITTED_INPUT_OVERWRITTEN; write a draft signal from onInput, or use defaultValue |
Migrate in steps
React and Solid components cannot be mixed in one tree. Move a route, page, or separate app root at a time:
- Create the Solid app shell with the Quick start.
- Move framework-independent code: types, validation, data clients, and utilities.
- Move leaf components and their local state.
- Move shared state and context.
- Move async data, loading states, and mutations.
- Remove the React root.