React Custom Hooks
React Custom Hooks provide an efficient means to encapsulate and share logic among components within React applications.
This package includes useful React custom hooks.
Table of Contents
Installation
You can install the package using npm:
npm install react-mkx-toolkit
Or using yarn:
yarn add react-mkx-toolkit
useKeyboard
The useKeyboard
hook is a custom React hook designed to simplify the handling of keyboard events within your React applications. With this hook, you can easily listen for specific keyboard inputs and execute callback functions in response to those inputs.
Usage
import { useKeyboard } from "react-mkx-toolkit";
const MyComponent = () => {
const handleKeyPress = () => {
console.log("The Enter key was pressed!");
};
useKeyboard("Enter", handleKeyPress);
return <>MyComponent</>;
};
export default MyComponent;
useRandomArray
This hook is useful for scenarios where you need to generate a sequence of numbers within a specified range,
such as creating test data, generating random values, or iterating through a range of numerical values.
Usage
import { useRandomArray } from "react-mkx-toolkit";
const MyComponent = () => {
const arr = useRandomArray(0, 10);
return <>MyComponent</>;
};
export default MyComponent;
Browser Support
 |  |  |  |  |  |
---|
Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 11 ✔ |
License
This project is licensed under the ISC License.
Author
Mani Kant Sharma