Skip to main content

useComputed()

Creates a new computed signal and returns it. The computed signal will be created only once.

See signia.computed

Example

type GreeterProps = {
firstName: Signal<string>
lastName: Signal<string>
}

const Greeter = track(function Greeter ({firstName, lastName}: GreeterProps) {
const fullName = useComputed('fullName', () => `${firstName.value} ${lastName.value}`)
return <div>Hello {fullName.value}!</div>
})

Signature

useComputed<Value>(name: string, compute: Function, deps: any[]): Computed<Value>;

Type parameters

  • Value

Parameters

NameType
namestring
compute() => Value
depsany[]

Returns

Computed<Value>

Defined in: signia-react/src/useComputed.ts:25

Signature

useComputed<Value, Diff>(
name: string,
compute: Function,
opts: ComputedOptions<Value, Diff>,
deps: any[]): Computed<Value>;

Type parameters

  • Value
  • Diff = unknown

Parameters

NameType
namestring
compute() => Value
optsComputedOptions<Value, Diff>
depsany[]

Returns

Computed<Value>

Defined in: signia-react/src/useComputed.ts:27