• A custom hook for fetching and managing the state of multiple reward types.

    Parameters

    • Optional params: {
          [key: string]: any;
      } = {}

      Optional parameters to filter or query reward types.

      • [key: string]: any

    Returns UseRewardTypesReturn

    The returning object contains:

    • refresh FetchRewardTypesMethod - Function to refresh the list of reward types.
    • rewardTypes: An array of reward types.
    • fetched: Boolean indicating whether the reward types have been successfully fetched.

    Implementation Details

    • Caching: API responses are cached for 300 seconds (300,000 ms) to minimize redundant network requests.
    • Effect Trigger: The useEffect hook is used to initiate the data fetch when the params object 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 { useRewardTypes } from "react-playmakers";

    const RewardTypesComponent = () => {
    const { rewardTypes, fetched, refresh } = useRewardTypes({ category: "promo" });

    return (
    <div>
    <h1>Reward Types</h1>
    {fetched ? (
    rewardTypes.length > 0 ? (
    <ul>
    {rewardTypes.map((rewardType) => (
    <li key={rewardType.id}>{rewardType.name}</li>
    ))}
    </ul>
    ) : (
    <p>No reward types found</p>
    )
    ) : (
    <p>Loading...</p>
    )}
    <button onClick={() => refresh()}>Refresh</button>
    </div>
    );
    };

Generated using TypeDoc