Skip to content

Architecture

This page describes how the package is structured and what is considered public API.

Published surface

Only import from the package root:

import { useDefaultReducer } from 'medhira-react-typescript-hooks';
import type { UseDefaultReducerReturn } from 'medhira-react-typescript-hooks';

The npm tarball includes compiled dist/ output. Internal reducer helpers live under dist/*/internal/ but are not documented or supported as public API.

Build pipeline

flowchart TB
    SRC["src/ TypeScript"] --> ESM["dist/esm (ES modules)"]
    SRC --> CJS["dist/cjs (CommonJS)"]
    ESM --> NPM["npm publish"]
    CJS --> NPM
    DOCS["docs/ Markdown"] --> RTD["Read the Docs"]
Output Entry Use case
ESM dist/esm/index.js Bundlers, modern Node
CJS dist/cjs/index.js require()
Types dist/esm/index.d.ts TypeScript consumers

useDefaultReducer flow

sequenceDiagram
    participant C as Component
    participant H as useDefaultReducer
    participant R as useReducer
    participant P as patch reducer

    C->>H: initialState S
    H->>R: createPatchReducer, S
    C->>H: patchState(Partial S)
    H->>P: dispatch patch action
    P->>P: shallow merge
    P-->>R: next state
    R-->>C: state

Design choices

Decision Rationale
useReducer under the hood Predictable updates; room to extend with more action types later
Private Symbol action type Action discriminator is not a public string constant
Shallow merge only Matches common form/object state patterns; keeps API simple
patchState naming Clear intent vs legacy multipleAction alias

What we do not expose

  • Reducer action type names or string literals
  • Source maps in published builds
  • Raw src/ in the npm package (files field lists dist only)