DocsBlog

Get Started

Components

Data Grid

Signals

Styling

Theming

↑↓Navigate
↵Select
EscClose
  • 1.8.0

  • Day

    Night

    Preview

    Switch mode
  • cerberus

    acheron

    elysium

    oceanus

Get Started
Components
Data Grid
Signals
Styling
Theming

Get started

OverviewReactivityData FetchingGlobal Stores

Primitives

Creating SignalsCreating QueriesCreating MutationsComputing Signal ValuesCreating EffectsContextual Signal StoresBatch UpdatesCleanup EffectsUntrack Signals

Hooks

Using QueriesUsing MutationsReading Primitive SignalsUsing SignalsUsing Store Instances

Components

Reactive Text

Computing Signal Values

Learn how to combine signals to create a single value in React.

  • source
View as Markdown
Open this page in Markdown
Anthropic
Open in Claude
Ask questions about this page
OpenAI
Open in ChatGPT
Ask questions about this page
import { createComputed } from '@cerberus/signals'

Usage

Sometimes you may want to create a new signal that is computed from other signal values. This is where the createComputed primitive comes in.

This API is similar to the native useMemo hook from React without the need for providing a depedency Array.

In this example, we create a computed signal based on two raw signals. Likewise, we utilize the createEffect primitive which sets the signal value without React getting involved.

Note

In order for createComputed to track signal subscriptions, it is required that Accessors are used in the body.

Loading example...

API

createComputed accepts a callback function and returns the value in a form of a Signal Accessor.

Important: be sure to use Accessor getters not values within a createComputed primitive. Ignoring to do so will cause stale values that will not be updated.

On this page

  • Usage
  • API
Edit this page on Github

Count: 0

Double Count: 0 is even