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}`, [
firstName,
lastName,
])
return <div>Hello {fullName.value}!</div>
})
Signature
useComputed<Value>(name: string, compute: Function, deps: any[]): Computed<Value>;
Type parameters
Value
Parameters
Name | Type |
---|---|
name | string |
compute | () => Value |
deps | any [] |
Returns
Computed
<Value
>
Defined in: signia-react/src/useComputed.ts:28
Signature
useComputed<Value, Diff>(
name: string,
compute: Function,
opts: ComputedOptions<Value, Diff>,
deps: any[]): Computed<Value>;
Type parameters
Value
Diff
=unknown
Parameters
Name | Type |
---|---|
name | string |
compute | () => Value |
opts | ComputedOptions <Value , Diff > |
deps | any [] |
Returns
Computed
<Value
>
Defined in: signia-react/src/useComputed.ts:30