use-async-toggle

A React toggle hook with support for async actions

github.com/kevjose/use-async-toggle

How to use

Please see the `/example` directory for usage details

Examples

Set and get async toggle status

Input:


const { on,pending, getTogglerProps, forwardError } = useAsyncToggle({});
/* * * * * * 
*
* on: indicates the status of the toggle , can be true or false, and is automatically set.
* pending: indicates the loading status in case of async functions, can be true or false, and is automatically set.
* getTogglerProps: can take a onClick function (both regular and async) and appends to the exisiting toggle logic
* forwardError(e): to be called in case error for custom onClick is being handled externally
*
* * * * * * */
          

Output:

Dark mode :isLoading: false