1.2.0 • Published 8 months ago

react-hook-executer v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

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)

License

MIT

1.2.0

8 months ago

1.1.4

8 months ago

1.1.3

8 months ago

1.1.2

8 months ago

1.1.1

8 months ago

1.1.0

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago