1.0.4 • Published 12 months ago

usecronjob v1.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
12 months ago

useCronJob The useCronJob hook is a custom React hook that allows you to schedule and perform tasks on an hourly, daily, monthly, or yearly basis. It provides a flexible and convenient way to automate recurring actions in your React applications.

Features Schedule tasks on an hourly, daily, monthly, or yearly basis. Set a specific time of day for daily tasks. Specify a particular date and time for monthly and yearly tasks. Support for custom scheduling logic. Easy integration with React functional components using the useEffect hook. Installation Install the useCronJob hook package from npm:

shell Copy code npm install use-cron-job Usage Here's an example of how you can use the useCronJob hook in your React component:

jsx Copy code import React from 'react'; import useCronJob from 'use-cron-job';

const MyComponent = () => { const task = () => { // Perform your task here console.log('Task executed!'); };

// Run the task every day at 12:00 PM useCronJob(task, 'daily', null, '12:00');

return ( // Your component JSX ); };

export default MyComponent; In the example above, the task function will be executed every day at 12:00 PM. You can modify the cronOptions array to customize the scheduling behavior based on your requirements.

API useCronJob(task, cronOptions) The useCronJob hook accepts two parameters:

task (function): The task or action to be performed on the scheduled intervals.

cronOptions (array): An array of options to define the scheduling behavior. The array should have the following format:

repeat (string): The repeat interval for the task. Available options are 'hourly', 'daily', 'monthly', 'yearly', or 'custom'. date (number or object): The date parameter for monthly or yearly tasks. For monthly tasks, provide the day of the month as a number (1-31). For yearly tasks, provide an object with month (1-12) and day (1-31) properties. time (string): The time of day for the task in 'HH:mm' format. Contributing Contributions, bug reports, and feature requests are welcome! Feel free to open issues and submit pull requests on the GitHub repository.

License This project is licensed under the MIT License.

1.0.4

12 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago