• A custom hook to fetch and manage a specific reward type by its ID.

    This hook provides a way to fetch, refresh, and track the state of a reward type using the provided API method. The data is cached for performance and efficiency.

    Parameters

    • Optional id: string

      The ID of the reward type to fetch. If not provided, the hook will not fetch data.

    Returns UseRewardTypeReturn

    The returning object contains:

    • refresh: FetchRewardTypeMethod - Function to refresh the reward type data.
    • rewardType: The current reward type or null if not yet fetched.
    • fetched: Boolean indicating whether the reward type has been fetched.

    Implementation Details

    • Caching: API responses are cached for 120 seconds (120,000 ms) to minimize redundant network requests.
    • Effect Trigger: The useEffect hook is used to initiate the data fetch when the id changes.
    • Error Handling: Any errors encountered during the fetch process are logged to the console and re-thrown with additional context for clarity.

    Example

    import { useRewardType } from "react-playmakers";

    const RewardTypeComponent = () => {
    const { rewardType, fetched, refresh } = useRewardType("RXXXXXXX");

    return (
    <div>
    {fetched ? (
    <div>
    <h1>Reward Type</h1>
    {rewardType ? (
    <p>{rewardType.name}</p>
    ) : (
    <p>No reward type found</p>
    )}
    <button onClick={() => refresh()}>Refresh</button>
    </div>
    ) : (
    <p>Loading...</p>
    )}
    </div>
    );
    };

Generated using TypeDoc