Function: useSignal

react.useSignal

useSignal<T>(initialValue): Signal<T>

React hook that creates and memoizes a persistent Signal tied to the component lifecycle.

Type parameters

Name Description
T The type of value held by the signal.

Parameters

Name Type Description
initialValue T Initial value of the signal.

Returns

Signal<T>

A reactive Signal instance.

Remarks

Automatically subscribes the host component to re-render whenever the signal's .value mutates.

Example

import React from 'react';
import { useSignal } from '@banksia/signals/react';

export const Counter: React.FC = () => {
  const count = useSignal(0);
  return (
    <button onClick={() => count.value++}>
      Count: {count.value}
    </button>
  );
};