@gibsonmurray/ghooks-cli
v1.0.8
Published
A CLI for managing React hooks in your project
Downloads
456
Readme
GHooks
GHooks is a command-line tool and React hooks library that allows you to easily add pre-built React hooks to your project.
Table of Contents
Installation
Install GHooks globally using your preferred package manager:
npm install -g @gibsonmurray/ghooks-cli
Command-Line Usage
After installation, you can use the ghooks
command in your terminal:
Add Hooks
To add hooks interactively:
ghooks add
To add a specific hook by name:
ghooks add <hook-name>
List Available Hooks
To list all available hooks:
ghooks list
Update Library & CLI
To update the hooks in the project:
ghooks update
To upgrade the CLI to the latest version:
ghooks upgrade
Hooks Library
The GHooks library provides the following hooks:
useArray
useAsync
useClickOutside
useClipboard
useCookie
useDarkMode
useDebounce
useDebug
useDeepEffect
useDocumentTitle
useDragDrop
useEventListener
useFetch
useFlipGSAP
useForm
useGeolocation
useGlobalState
useHover
useIdle
useImageLoad
useKeyPress
useLockScroll
useLongPress
useMediaDevices
useMediaQuery
useMounted
useMouse
useOnlineStatus
useOnScreen
useOrientation
usePermission
usePrevious
useRenderCount
useScript
useSize
useStateHistory
useStateValidation
useLocalStorage
useSessionStorage
useTimeout
useToggle
useUnmounted
useUpdated
useWindowSize
Library Usage
You can also use the hooks directly in your React projects:
- Install the library:
npm install @gibsonmurray/react-hooks
- Import the hook you need:
import { useDebounce } from "@gibsonmurray/react-hooks"
const MyComponent = () => {
const [value, setValue] = useState("")
const debouncedValue = useDebounce(value, 500)
// ... rest of your component
}
CLI Implementation
The GHooks CLI is implemented in the index.ts
file, which provides the following functionality:
- Adding Hooks: Users can add hooks interactively or by specifying a hook name.
- Listing Hooks: Displays all available hooks from the repository.
- Updating Hooks: Updates existing hooks in the project to their latest versions.
- Upgrading CLI: Upgrades the GHooks CLI to the latest version.
- Version Information: Displays the current version of the CLI.
The CLI uses several dependencies:
commander
: For parsing command-line arguments and defining commands.inquirer
: For interactive command-line user interfaces.axios
: For making HTTP requests to fetch hook data.chalk
: For colorful console output.semver
: For semantic versioning comparisons.
The main commands implemented in index.ts
are:
ghooks add [hookName]
: Adds one or more hooks to the project.ghooks list
: Lists all available hooks.ghooks update
: Updates existing hooks in the project.ghooks upgrade
: Upgrades the GHooks CLI to the latest version.ghooks version
: Displays the current version of the CLI.
The CLI fetches hook data from the GitHub repository, ensuring that users always have access to the latest versions of the hooks.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.