https://github.com/trevonerd/react-bacon
BACON 🥓 - Boilerplate for Advanced Creation Of NPM packages
https://github.com/trevonerd/react-bacon
Last synced: 2 months ago
JSON representation
BACON 🥓 - Boilerplate for Advanced Creation Of NPM packages
- Host: GitHub
- URL: https://github.com/trevonerd/react-bacon
- Owner: trevonerd
- Created: 2024-07-28T22:35:33.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-07-29T00:06:09.000Z (10 months ago)
- Last Synced: 2025-01-24T10:08:29.726Z (4 months ago)
- Language: JavaScript
- Homepage:
- Size: 105 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# OrchestRate
🎼 OrchestRate: The Maestro of React Effects! ðŸŽ
OrchestRate is a React library for orchestrating and executing effects with priorities and delays. It provides a simple way to manage complex sequences of asynchronous operations in your React applications.
## Installation
```bash
npm install orchestrate
```or
```bash
yarn add orchestrate
```## Features
- Orchestrate multiple effects with different priorities
- Add pre and post delays to effects
- Set timeouts for effect execution
- Cancel specific effects
- Debug mode for detailed logging## Usage
### Basic Setup
Wrap your app or a part of it with the `OrchestRateProvider`:
```jsx
import { OrchestRateProvider } from 'orchestrate';function App() {
return {/* Your app components */};
}
```### Using the Hook
Use the `useOrchestRate` hook to access the orchestration functions:
```jsx
import { useOrchestRate } from 'orchestrate';function MyComponent() {
const { orchestrate, execute, cancel } = useOrchestRate();const handleClick = () => {
orchestrate(
'effect1',
async () => {
// Your effect logic here
},
{ priority: 1 }
);orchestrate(
'effect2',
async () => {
// Another effect
},
{ priority: 2, preDelay: 1000 }
);execute();
};return Run Effects;
}
```### Using the Effect Hook
For simpler cases, you can use the `useOrchestRateEffect` hook:
```jsx
import { useOrchestRateEffect } from 'orchestrate';function MyComponent() {
useOrchestRateEffect(
'myEffect',
async () => {
// Your effect logic here
},
{ priority: 1 }
);return
Effect will run on mount;
}
```## API
### `OrchestRateProvider`
A context provider component that should wrap your app or the part of your app that uses OrchestRate.
Props:
- `children`: React nodes
- `debug` (optional): Boolean to enable debug logging### `useOrchestRate`
A hook that returns an object with the following methods:
- `orchestrate(id: string, effect: Function, options?: Object)`: Adds an effect to the queue
- `execute(): Promise`: Executes all queued effects
- `cancel(id: string)`: Cancels a specific effect### `useOrchestRateEffect`
A hook that combines `orchestrate` and `execute` for simpler use cases.
Parameters:
- `id: string`: Unique identifier for the effect
- `effect: Function`: The effect to be executed
- `options?: Object`: Additional options (priority, preDelay, postDelay, timeout)## License
MIT
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.