A collection of essential React hooks, state management utilities, and helper functions for modern React applications.
npm install @munirmardinli_org/react-utils
# or
yarn add @munirmardinli_org/react-utils
# or
pnpm add @munirmardinli_org/react-utils
src/
├── hooks/ # Custom React hooks (useAuth, useBreakpoint, etc.)
│ ├── useAuthHook.ts
│ ├── useBreakpoint.ts
│ ├── useLanguageEffect.ts
│ ├── usePostRequest.ts
│ ├── useThemeFromCookies.ts
├── stores/
│ ├── changeLanguageStore.ts
│ ├── changeModeStore.ts
│ └── selectedLanguageMenuStore.ts
│ └── snackbarStore.ts
│ └── useCookieStore.ts
├── utils/ # Helper functions
│ └── globals.ts
├── types.d.ts # Type declarations
└── index.ts # Public API exports
🎨 useThemeStore
Manages application theme with persistence.
Features:
const { mode, toggleMode } = useThemeStore();
// Example usage
<button onClick={toggleMode}>
Switch to {mode === "light" ? "dark" : "light"} mode
</button>;
🌐 useLanguageStore
Handles multilingual support with:
const { languageSelected, setLanguage } = useChangeLanguageStore();
💬 useSnackStore
Global notification system.
(error | warning | success | info)
const { setSnack } = useSnackStore();
// Basic usage
setSnack("Profile updated!", "success");
// With action
setSnack({
message: "File deleted",
severity: "warning",
action: { label: "Undo", onClick: handleUndo },
});
useCookieStore
Secure authentication token management.
const { authToken, setAuthToken, removeAuthToken } = useCookieStore();
// Login flow
const handleLogin = async () => {
const token = await authService.login();
setAuthToken(token);
};
// Logout
const handleLogout = () => {
removeAuthToken();
};
useChangeLanguageStore
Handles multilingual support with automatic persistence.
Features
const { languageSelected, setLanguage } = useChangeLanguageStore();
<select value={languageSelected} onChange={(e) => setLanguage(e.target.value)}>
<option value="en">English</option>
<option value="fr">Français</option>
</select>;
Handles language selection persistence by:
// Basic usage:
useLanguageEffect();
// With store access:
const { languageSelected } = useChangeLanguageStore();
useLanguageEffect();
Manages theme synchronization by:
// Basic usage:
useThemeFromCookies();
// With store access:
const { mode } = useThemeStore();
useThemeFromCookies();
Responsive design helper with TypeScript support.
const { isMobile, current } = useBreakpoint();
return (
<div className={isMobile ? "mobile-layout" : "desktop-layout"}>
Current breakpoint: {current}
</div>
);
Return Type:
type BreakpointResult {
isMobile: boolean; // width < 768px
isTablet: boolean; // 768px ≤ width < 1024px
isDesktop: boolean; // width ≥ 1024px
current: 'mobile' | 'tablet' | 'desktop'; // Current breakpoint
}
JWT authentication with automatic token validation.
const { user, isLoading } = useAuthHook();
if (isLoading) return <Spinner />;
if (!user) return <LoginPage />;
return <WelcomeBanner name={user.name} />;
Features:
Type-safe POST requests with built-in state.
// With auto-execution
const { data } = usePost<User>({
path: "/api/users",
body: { name: "Alice" },
});
// Manual execution
const { sendPostRequest } = usePost<Product>();
const handleSubmit = () =>
sendPostRequest({ path: "/products", body: product });
Set environment variables for cookie settings:
COOKIE_MAX_AGE=2592000 # 30 days
COOKIE_PATH=/ # Accessible site-wide
COOKIE_SAME_SITE=lax # CSRF protection
MIT License © Munir Mardinli
MIT License
Copyright (c) 2025 Munir Mardinli
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.