Function: useReactive

react.useReactive

useReactive<T>(target): T

React hook that subscribes the host component to changes in a reactive target object or store.

Type parameters

Name Type Description
T extends object The type of reactive target object or domain store.

Parameters

Name Type Description
target T The reactive object, domain model, or signal container to observe.

Returns

T

The same reactive target object reference.

Remarks

Whenever properties of the passed reactive object are accessed and mutated, this hook triggers a component re-render.

Example

import React from 'react';
import { useReactive } from '@banksia/signals/react';
import { userStore } from './user-store';

export const UserHeader: React.FC = () => {
  const store = useReactive(userStore);
  return <h2>Welcome, {store.user.name}</h2>;
};