Rehooks

Initialization

Learn how to interact with the CLI

Initialization

To use the CLI, you can execute it directly within the latest version:

Terminal
npx rehooks-cli@latest

Guide

At first, you must initialize the Rehooks configuration. To do this, run the following command into your project's directory:

Terminal
npx rehooks-cli init

You'll be prompted to choose a path for the hooks to be imported. If you want use a custom path for the hooks directory, you can pass it as an argument to the init command.

Terminal
npx rehooks-cli init ./path/somewhere

Rehooks requires React version 18 or higher. If your project uses a lower version, you will encounter compatibility issues. Also your project must include package.json file.

Now It's time to import hooks into your project. To achieve this you must run the add command.

Terminal
npx rehooks-cli add

This command will ask you to select the hooks you want to import from the list of available hooks through the API. You can select multiple hooks by pressing the space key.

You can pick hooks up to 10 at a time, due to the limitation of the API.

If you want to pass hooks manually, you can do so by running the following command:

Terminal
npx rehooks-cli add useFocus useFetch useWindowSize useEventListener

List

To list all available hooks in the API, you can run the following command:

Terminal
npx rehooks-cli list

The result will be displayed in the terminal with the description of each hook.

Terminal
Total Hooks: 32
 
Hooks List (32):
useFocus: Tracks the focus state of a specified element.
...

Options

These are the options available in the CLI.

OptionDescription
-v, --versionDisplays the current version of the CLI
-h, --helpDisplays help for command

Commands

CommandDescription
init [options] [path]Initialize the Rehooks configuration
add [options] [hooks]Add custom hooks to your project
listList all available hooks in the API
help [command]Displays help for a specific command

Init

Arguments

ArgumentDescription
pathSpecify a custom path for hooks directory

Options

OptionDescription
-f, --forceForce overwrite existing configuration without prompt
-c, --config <path>Specify a custom path for rehooks.json
-h, --helpDisplays help for command

Add

Arguments

ArgumentDescription
hooksSpecify hooks to add

Options

OptionDescription
-f, --forceForce overwrite existing hook files without prompt
-h, --helpDisplays help for command

On this page