Skip to content

Latest commit

 

History

History
150 lines (97 loc) · 5.4 KB

File metadata and controls

150 lines (97 loc) · 5.4 KB

⚠️ This library is in beta version might be all hooks are not yet ready! we will soon dispatch hooks with bulletproof tests 🚀


Logo


npm Discord

Discord: https://discord.gg/DTJV27BYwA

React Smart Utils Library

A lightweight collection of production-ready React hooks and utility functions. Zero dependencies. SSR-safe. StrictMode-friendly.


Table of Contents


Installation

To install the React Smart Utils library, use npm or yarn:

npm install react-smart-utils

or

yarn add react-smart-utils

Features

  • Custom Hooks: Reusable React hooks to solve common use cases.
  • Utility Functions: Handy utilities to simplify everyday coding tasks.
  • TypeScript Support: Fully typed with TypeScript for a smooth developer experience.
  • Tree-shakable: Only include what you need, minimizing bundle size.

🪝 Hooks – Description & Usage

Hook Description React Native Support Mobile Alternative / Notes
useToggle Manage boolean state with helper actions ✅ Yes Works out of the box
usePrevious Get previous value of state or prop ✅ Yes Works out of the box
useLocalStorage Persist state in localStorage ❌ No Use AsyncStorage
useCountdown Countdown timer with controls ✅ Yes Works out of the box
useDebounceValue Debounce changing values ✅ Yes Works out of the box
useUpdateEffect Effect that skips initial render ✅ Yes Works out of the box
useRunOnlyOnce Run logic exactly once (StrictMode safe) ✅ Yes Works out of the box
useUnmount Run cleanup logic on unmount ✅ Yes Works out of the box
useIsMounted Prevent state updates after unmount ✅ Yes Works out of the box
useClipboard Copy text to clipboard ⚠️ Partial Use expo-clipboard / RN Clipboard
useNetwork Track online/offline state ⚠️ Partial Use @react-native-community/netinfo
useWindowSize Track window dimensions ❌ No Use useWindowDimensions

🧰 Utils (Web & Native)

Utility Description React Native Support Notes
clamp Clamp a number between min & max ✅ Yes Pure function
hasKey Type-safe object key check ✅ Yes TS-friendly
isNull Check if value is null ✅ Yes Pure function
isUndefined Check if value is undefined ✅ Yes Pure function
sample Get random item from array ✅ Yes Pure function
sleep Async delay helper ✅ Yes Works everywhere
throttle Throttle function execution ✅ Yes Platform-agnostic
toLower Convert string to lowercase ✅ Yes Safe wrapper
toUpperCase Convert string to uppercase ✅ Yes Safe wrapper
uniqueArray Remove duplicate array values ✅ Yes Uses Set

Contributing

We welcome contributions! Please follow the instructions below to set up the project for development and make your contributions.

  1. Fork the repositoryon GitHub.
  2. Clone your forked repository:
git clone https://github.com/your-username/react-smart-utils.git
cd package
yarn install

3.Test your functions or hooks in smart-app:

cd smart-app
yarn install
yarn dev

Note: You can push example code as it helps in preparing documents (When Raise PR you must paste the path in PR description)

4.Create a new branch for your feature:

git checkout -b feature/my-new-feature
  1. Make your changes, then commit and push:
git commit -m "Add new feature"
git push origin feature/my-new-feature

Submit a Pull Request with a detailed explanation of your changes.