Overview
The@workspace/core package is the shared core module that provides common functionality across all apps and packages in the monorepo. It is designed to be isomorphic, meaning it can be used in both browser and server environments.
Installation
The core package is available as a workspace package and can be imported in any app or package within the monorepo:Package Structure
The core package exports modules organized by category:Exports
The package uses path-based exports to allow fine-grained imports:APIs
API client instances for external services:@workspace/core/apis/auth- Authentication API client@workspace/core/apis/better-auth- Better Auth integration@workspace/core/apis/cdn- CDN API client@workspace/core/apis/core- Core API utilities
Hooks
React hooks for common functionality:State Management Hooks
State Management Hooks
use-controllable-value- Manage controlled/uncontrolled component stateuse-reset-state- State with reset functionalityuse-local-storage-state- Persist state in localStorageuse-session-storage-state- Persist state in sessionStorageuse-history-travel- State with undo/redo historyuse-selections- Manage multi-select state
Lifecycle Hooks
Lifecycle Hooks
use-mount- Execute callback on component mountuse-update- Execute callback on component updateuse-update-effect- useEffect that skips initial mountuse-update-layout-effect- useLayoutEffect that skips initial mount
Timing Hooks
Timing Hooks
use-interval- setInterval with React lifecycle integrationuse-timeout- setTimeout with React lifecycle integrationuse-raf-interval- requestAnimationFrame-based intervaluse-raf-timeout- requestAnimationFrame-based timeout
Utility Hooks
Utility Hooks
use-copy-to-clipboard- Copy text to clipboarduse-color-mode- Manage light/dark themeuse-media-query- Respond to media query changesuse-auto-scroll- Auto-scroll functionalityuse-dynamic-list- Dynamic list managementuse-latest- Always get the latest valueuse-memoized-fn- Memoize function referencesuse-multiple-refs- Combine multiple refs
Services
Service classes for common functionality:HTTP Service
A wrapper around theky HTTP client:
Utils
Utility functions organized by category:@workspace/core/utils/core- Core utility functions@workspace/core/utils/cookie- Cookie management utilities@workspace/core/utils/date- Date formatting and manipulation@workspace/core/utils/dom- DOM manipulation utilities@workspace/core/utils/invariant- Invariant assertions@workspace/core/utils/logger- Logging utilities
Logger
Structured logging with color-coded severity levels:Constants
Shared constants and configuration:@workspace/core/constants/core- Core constants@workspace/core/constants/date- Date-related constants@workspace/core/constants/http- HTTP status codes and headers
Types
Shared TypeScript type definitions:@workspace/core/types/core- Core type definitions
Libraries
Configured third-party library integrations:@workspace/core/libs/i18n/init- i18n initialization@workspace/core/libs/i18n/define-translation- Translation helpers@workspace/core/libs/i18n/locales/en-US- English translations@workspace/core/libs/i18n/locales/id-ID- Indonesian translations
Assets
Shared static assets:@workspace/core/assets/fonts/*- Lato font family (regular, italic, bold)@workspace/core/assets/images/*- Shared images
Peer Dependencies
The core package requires the following peer dependencies:Usage Examples
Using Hooks
Using Services
Using Utilities
Best Practices
Use Path Imports
Always import specific modules using path-based exports instead of importing the entire package.
Isomorphic Code
The core package is designed to work in both browser and Node.js environments. Avoid platform-specific code.
Type Safety
Leverage TypeScript types exported from the package for better type safety.
Peer Dependencies
Ensure all peer dependencies are properly installed in your consuming package.
