react-hook-executer
v1.2.0
Published
Allows a programmer to easily register custom hooks dynamically in React.js.
Downloads
603
Maintainers
Readme
React Hooks Executer
The HooksExecuter class provides a streamlined way to dynamically register and manage custom React hooks. It simplifies hook registration and usage by offering an efficient mechanism to initialize hooks, store their state, and retrieve their values as needed. This allows developers to organize and manage hooks in a reusable and declarative manner.
Features
- React Component Integration: The ReactHooksWrapper acts as a centralized initializer for all registered hooks, ensuring hooks are executed as part of the React lifecycle.
- Dynamic Hook Registration: Easily register custom hooks at runtime with validation to ensure correct usage.
- State Storage for Hooks: Automatically execute registered hooks and store their state for future retrieval.
- Error Validation: Ensures registered hooks are valid functions and identifiers are proper strings.
Installation
Install the package with npm:
npm install react-hooks-executer
Parameters
Registers a new hook dynamically.
setHook(name: string, hookFunction: () => any): this
name: A unique string identifier for the hook. hookFunction: A React hook function to be registered.
Retrieves the stored state of a previously registered hook.
getHook(name: string): any
name: The string identifier of the registered hook.
Usage/Examples
- setHook:
import { setHook } from 'react-hooks-executer';
setHook('useCustomHook', () => {
const [count, setCount] = React.useState(0);
React.useEffect(() => {
console.log('Custom Hook Executed');
}, []);
return { count, setCount };
});
- getHook:
import { getHook } from 'react-hooks-executer';
const customHookState = getHook('useCustomHook');
console.log('Shivaji',customHookState.count);
customHookState.setCount(10);
Authors
- Shivaji : (Sr. React Developer)
- Shyamal : (Sr. React Developer)