Reintent
/

useChoiceStatus

Reads a choice's value with where it came from and its status.

Call Signature

function useChoiceStatus<T>(c, opts): ChoiceStatus<T>;

Defined in: packages/core/src/intent/hooks.ts

The same choice as useChoose, with its source and status in this evaluation. Reports one read and the same requests. These fields participate in skipping; distributions do not. Read a distribution through intent.explain(id, provide).dist in the host.

A component may draw a different appearance for an unresolved or model-supplied value. It must keep the returned value: collapse belongs to the surrounding <Resolve>, not the hook.

Type Parameters

Type Parameter
T

Parameters

ParameterType
c| Choices<T> | Generation<T> | Judged<T>
optsChooseOptions<T>

Returns

ChoiceStatus<T>

Example

import {
  choices,
  createIntent,
  host,
  useChoiceStatus,
  type HostNode,
} from '@reintent/core';

function Reply() {
  const tone = useChoiceStatus(choices('formal', 'warm'), {
    of: 'r1',
    name: 'tone',
    defaultValue: 'warm',
  });
  return host('reply', { tone: tone.value, source: tone.source, status: tone.status });
}

const intent = createIntent({ program: <Reply /> });
const props = () => (intent.realize().tree as HostNode).props;
console.log(props().tone, props().source, props().status); // → 'warm' 'default' 'unresolved'
intent.decide({ of: 'r1', name: 'tone' }, 'formal');
console.log(props().tone, props().source, props().status); // → 'formal' 'decision' 'decided'

Call Signature

function useChoiceStatus<R>(ref, ...opts): StatusOf<R>;

Defined in: packages/core/src/intent/hooks.ts

A declared choice by its handle (0015 §5.1); undefined where it does not apply.

Type Parameters

Type Parameter
R extends Declared

Parameters

ParameterType
refR
...optsDeclaredArgs<R>

Returns

StatusOf<R>

Call Signature

function useChoiceStatus<T>(
   id, 
   c, 
   opts?
): ChoiceStatus<T>;

Defined in: packages/core/src/intent/hooks.ts

A choice by its identity, its possibilities and how it is asked here, as useChoose (0092 §4).

Type Parameters

Type Parameter
T

Parameters

ParameterType
idId | Declared
c| Choices<T> | Generation<T> | Judged<T>
opts?Omit<ChooseOptions<T>, "of" | "name">

Returns

ChoiceStatus<T>


Last updated on

Edit on GitHub