@@ -4,26 +4,36 @@ import { useContext, useMemo, useState } from 'react';
4
4
5
5
import { kitContext , useUiKitStateValue } from '../contexts/kitContext' ;
6
6
7
- type UiKitState = {
7
+ type UiKitState <
8
+ TElement extends UiKit . ActionableElement = UiKit . ActionableElement
9
+ > = {
8
10
loading : boolean ;
9
11
setLoading : ( loading : boolean ) => void ;
10
12
error ?: string ;
11
- value : string | number | undefined ;
13
+ value : UiKit . ActionOf < TElement > ;
12
14
} ;
13
15
14
- const hasInitialValue = < T extends UiKit . ActionableElement > (
15
- element : T
16
- ) : element is T & { initialValue : number | string } =>
16
+ const hasInitialValue = < TElement extends UiKit . ActionableElement > (
17
+ element : TElement
18
+ ) : element is TElement & { initialValue : number | string } =>
17
19
'initialValue' in element ;
18
20
19
- const hasInitialOption = < T extends UiKit . ActionableElement > (
20
- element : T
21
- ) : element is T & { initialOption : UiKit . Option } => 'initialOption' in element ;
21
+ const hasInitialOption = < TElement extends UiKit . ActionableElement > (
22
+ element : TElement
23
+ ) : element is TElement & { initialOption : UiKit . Option } =>
24
+ 'initialOption' in element ;
22
25
23
- export const useUiKitState : < T extends UiKit . ActionableElement > (
24
- element : T ,
26
+ export const useUiKitState : < TElement extends UiKit . ActionableElement > (
27
+ element : TElement ,
25
28
context : UiKit . BlockContext
26
- ) => [ UiKitState , any ] = ( rest , context ) => {
29
+ ) => [
30
+ state : UiKitState < TElement > ,
31
+ action : (
32
+ pseudoEvent ?:
33
+ | { target : EventTarget }
34
+ | { target : { value : UiKit . ActionOf < TElement > } }
35
+ ) => void
36
+ ] = ( rest , context ) => {
27
37
const { blockId, actionId, appId } = rest ;
28
38
const {
29
39
action,
0 commit comments