Function useUserRewardsByReward

  • Custom React hook to fetch user rewards specific to a given reward.

    This hook is a wrapper around the useUserRewards hook, automatically passing the rewardId to filter user rewards for that specific reward. You can also pass additional parameters to further filter or modify the data fetching behavior.

    Parameters

    • rewardId: string

      The ID of the reward for which user rewards should be fetched.

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

      Optional additional parameters that will be passed along to the useUserRewards hook.

      • [key: string]: any

    Returns UseUserRewardsReturn

    The returning object contains:

    • refresh: FetchUserRewardsMethod - Function to refresh or re-fetch the user rewards data.
    • userRewards: The current list of user rewards.
    • fetched: Boolean indicating whether the user rewards data has been successfully fetched.

    Implementation Details

    • Parameters: Accepts a required rewardId and optional additional params to further refine the data fetch.
    • Delegation: The hook delegates the fetching logic to useUserRewards, passing along the rewardId.
    • Caching: Caching mechanisms from useUserRewards are inherited to optimize network performance.

    Example

    import { useUserRewardsByReward } from 'react-playmakers';

    const RewardUserRewards: React.FC = () => {
    const { userRewards, fetched, refresh } = useUserRewardsByReward('rXXXXXXX');

    useEffect(() => {
    if (!fetched) {
    console.log("Fetching rewards for the reward...");
    }
    }, [fetched]);

    const handleRefresh = async () => {
    await refresh();
    console.log("User rewards refreshed.");
    };

    return (
    <div>
    {fetched ? (
    <div>
    <h2>Reward User Rewards</h2>
    <ul>
    {userRewards.map((reward, index) => (
    <li key={index}>{reward.name}</li>
    ))}
    </ul>
    </div>
    ) : (
    <p>Loading...</p>
    )}
    <button onClick={handleRefresh}>Refresh Rewards</button>
    </div>
    );
    };

Generated using TypeDoc