@@ -5,9 +5,9 @@ import { createContext, useContext, useState } from 'react';
5
5
import { noop } from '../noop' ;
6
6
import type { Foxact } from '../types' ;
7
7
8
- type ProviderProps < T > = Foxact . PropsWithChildren < {
9
- initialState ?: T
10
- } > ;
8
+ interface ProviderProps < T > {
9
+ initialState ?: T | ( ( ) => T )
10
+ }
11
11
12
12
/** @see https://foxact.skk.moe/context-state */
13
13
export function createContextState < T > ( initialState : T ) : [
@@ -17,7 +17,7 @@ export function createContextState<T>(initialState: T): [
17
17
StateContext : React . Context < T >
18
18
] ;
19
19
export function createContextState < T > ( ) : [
20
- Provider : React . ComponentType < Required < ProviderProps < T > > > ,
20
+ Provider : React . ComponentType < Foxact . PropsWithChildren < Required < ProviderProps < T > > > > ,
21
21
useValue : ( ) => T ,
22
22
useSetValue : ( ) => React . Dispatch < React . SetStateAction < T > > ,
23
23
StateContext : React . Context < T >
@@ -29,7 +29,7 @@ export function createContextState(initialState?: unknown): unknown {
29
29
const useValue = ( ) => useContext ( StateContext ) ;
30
30
const useSetValue = ( ) => useContext ( DispatchContext ) ;
31
31
32
- const Provider = ( { children, initialState : initialStateFromProps } : ProviderProps < unknown > ) => {
32
+ const Provider = ( { children, initialState : initialStateFromProps } : Foxact . PropsWithChildren < ProviderProps < unknown > > ) => {
33
33
const [ value , setValue ] = useState ( ( initialStateFromProps ?? initialState ) ) ;
34
34
35
35
return (
0 commit comments