This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
@42.nl/react-spring-enums is an npm library for sharing enums between a React frontend and a Java Spring Boot backend. It fetches enum definitions from a Spring Boot REST endpoint and provides them via React hooks and context.
- Run all checks:
npm test(runs lint + TypeScript check + Vitest with coverage) - Run tests only:
npm run test:coverage - Run tests in watch mode:
npm start - Run a single test file:
npx vitest run tests/hooks.test.ts - Type check:
npm run test:ts - Lint:
npm run lint - Build (compile to lib/):
npm run tsc - Release:
npm run release(builds then runsnpfor npm publish)
The library uses a custom pub/sub service pattern (no Redux/external state) with React hooks for consumption:
- config.ts - Module-scoped singleton holding
Config(enum URL) and theEnumsServiceinstance.configureEnums()must be called before anything else. - service.ts -
makeEnumsService()creates a lightweight pub/sub store:subscribe/unsubscribe/setEnums/getState. ManagesEnumsState<T>({ enums: T }). - load-enums.ts -
loadEnums()fetches enums from the configured URL via@42.nl/spring-connect'sget()and pushes them into the service. - hooks.tsx -
useEnums<T>()subscribes to the service and returns full state.useEnum<T>(name)returns a single enum's values or throwsMissingEnumException. - provider.tsx -
EnumsProvider/EnumsContextwrapsuseEnumsin React context for consumer components. - formUtils.ts -
filterEnumValues()andgetEnumsAsPage()for searching/paginating enum values. Supports both simple string enums and complex enums ({ code, displayName }). - models.ts - Type definitions:
Enums,EnumValues,EnumValue,ComplexEnumType.
- Peer dependency:
@42.nl/spring-connect(>=6.1 <8.0) - providesget()for HTTP andpageOf()for pagination. - 100% test coverage required (branches, functions, lines, statements) - enforced by Vitest config.
- ESLint 9 flat config in
eslint.config.mjs— usestypescript-eslint,eslint-plugin-react, andeslint-plugin-react-hooks. - Formatting: Prettier with single quotes, no trailing commas.
- Pre-commit hook: Husky runs
lint-staged(Prettier) on staged files insrc/andtests/. - TypeScript strict mode is enabled. Output targets ES6/CommonJS to
lib/. - Generic type parameter
Tis used throughout to allow custom enum type definitions beyond the defaultEnumstype.