Function useSinglerunAction

This function is a custom hook that helps to handle asynchronous actions and manage loading and error states.

  • Type Parameters

    • Data extends unknown = any

      The type of data that the asynchronous action will return.

    • Payload extends unknown = any

      The type of payload that the asynchronous action accepts.

    Parameters

    • run: (p: Payload) => Data | Promise<Data>

      The asynchronous action to be executed.

    • Optionaloptions: IParams

      Additional options for the hook.

      • onLoadStart

        Callback function called when the asynchronous action starts.

      • onLoadEnd

        Callback function called when the asynchronous action ends.

      • fallback

        Callback function called when an error occurs, if throwError is set to false.

      • throwError

        Flag to determine whether to throw an error or call the fallback function when an error occurs. Default is true.

    Returns IResult<Data, Payload>

    • An object containing the loading state, error state, and an execute function to execute the asynchronous action.