diff --git a/src/index.ts b/src/index.ts index ffcac791..086916f8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -74,6 +74,7 @@ export * from './useWindowSize/index.js'; export {isStrictEqual, truthyAndArrayPredicate, truthyOrArrayPredicate} from './util/const.js'; export type {EffectCallback, EffectHook} from './util/misc.js'; export {resolveHookState} from './util/resolve-hook-state.js'; +export type {InitialState, NextState} from './util/resolve-hook-state.js'; // Types export type * from './types.js'; diff --git a/src/util/resolve-hook-state.ssr.test.ts b/src/util/resolve-hook-state.ssr.test.ts new file mode 100644 index 00000000..15b0e848 --- /dev/null +++ b/src/util/resolve-hook-state.ssr.test.ts @@ -0,0 +1,19 @@ +import type {InitialState, NextState} from '../index.js'; +import {describe, expect, it} from 'vitest'; +import {resolveHookState} from '../index.js'; + +describe('public hook state types', () => { + it('should export initializer and updater types from the package root', () => { + const initialState: InitialState = () => 123; + const nextState: NextState = (previousState) => previousState + 1; + + expect(resolveHookState(initialState)).toBe(123); + expect(resolveHookState(nextState, 123)).toBe(124); + }); + + it('should support a different previous state type for mediated updates', () => { + const nextState: NextState = (previousState) => previousState.length; + + expect(resolveHookState(nextState, 'foo')).toBe(3); + }); +});