Reactive utilities

refresh

Edit this page
import { refresh } from "solid-js"
// Thunk form — re-runs an expression
function refresh<T>(fn: () => T): T
// Refreshable form — recomputes a derived signal/store/projection
function refresh(target: Refreshable): void

refresh() explicitly re-runs derived reads when you know the underlying source-of-truth may have changed (e.g., after a server write completes).


Forms

Refreshable form

Requests recomputation for a derived computation. Works with any "refreshable" target — a derived store, async memo, or projection created with a function argument:

const [todos] = createStore(() => api.getTodos(), { list: [] })
// After a server write, refresh the store
refresh(todos)

Refreshable targets are computations created with a function form: createStore(() => ...), createMemo(() => ...) (async), and createProjection. These internally carry a refresh symbol that refresh() uses to trigger recomputation.

Thunk form

Re-runs an arbitrary expression:

refresh(() => query.user(id()))

Usage with action

refresh is typically used inside an action after async work completes:

import { action, refresh } from "solid-js"
import { createStore } from "solid-js/store"
const [todos] = createStore(() => api.getTodos(), { list: [] })
const addTodo = action(function* (todo) {
yield api.addTodo(todo)
refresh(todos) // re-fetch the todos
})

refresh can also be called outside of actions — for example, in response to a WebSocket message or other external event — to trigger recomputation of derived data.


Replaces refetch

In Solid 1.x, createResource returned a refetch method. refresh() is the general replacement:

// 1.x
const [data, { refetch }] = createResource(fetchData)
refetch()
// 2.0
const data = createMemo(() => fetchData())
refresh(data)
Report an issue with this page