Optional
projectId: stringThe ID of the project for which rewards are fetched. If omitted, rewards are not project-specific.
Optional
params: { Query parameters to filter or modify the rewards request.
The returning object contains:
fetched
: Boolean indicating whether the rewards have been successfully fetched.rewards
: The list of rewards, extended with additional methods.refresh
: FetchRewardsMethod - Function to refresh the rewards list.useEffect
hook initiates the fetch process when the projectId
or params
change.delete
, push
, redeem
) for
easier handling within UI components.import { useRewards } from 'react-playmakers';
const RewardsList = () => {
const { rewardList, refresh, fetched } = useRewards('pXXXXXXXX', { status: 'active' });
useEffect(() => {
if (fetched) {
console.log('Fetched rewards:', rewardList);
}
}, [fetched, rewardList]);
return (
<div>
<h1>Rewards</h1>
<button onClick={() => refresh(true)}>Refresh Rewards</button>
<ul>
{rewardList.map(reward => (
<li key={reward.id}>
{reward.name} - {reward.points} points
<button onClick={reward.delete}>Delete</button>
<button onClick={() => reward.push({ name: 'Updated Name' })}>
Update
</button>
<button onClick={reward.redeem}>Redeem</button>
</li>
))}
</ul>
</div>
);
};
Generated using TypeDoc
Custom React hook for managing a list of rewards associated with a project.
This hook provides functionality to fetch, update, delete, and redeem rewards. It also handles caching, state updates, and error handling for smoother integration with APIs and user interfaces.