| 65 | export type Hook = HookEffect & HookState<unknown> & HookReducer<any, unknown> & HookRef<unknown> & HookCallback<any> & HookContext |
| 66 | |
| 67 | export function useState<S> (initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>>] { |
| 68 | if (isFunction(initialState)) { |
| 69 | initialState = initialState() |
| 70 | } |
| 71 | const hook = getHooks(Current.index++) as HookState<S> |
| 72 | if (!hook.state) { |
| 73 | hook.component = Current.current! |
| 74 | hook.state = [ |
| 75 | initialState, |
| 76 | (action) => { |
| 77 | hook.state[0] = isFunction(action) ? action(hook.state[0]) : action |
| 78 | hook.component._disable = false |
| 79 | hook.component.setState({}) |
| 80 | } |
| 81 | ] |
| 82 | } |
| 83 | return hook.state |
| 84 | } |
| 85 | |
| 86 | export function useReducer<R extends Reducer<any, any>, I> ( |
| 87 | reducer: R, |