Hooks
usePrize
Home
Getting Started
Hooks
usePrize
The usePrize hook is is a convenient way to access the prizes for the App.
Usage
Get Prizes
import { usePrizes, PrizeResource } from '@useawards/useaward-expo';
import { useEffect, useState } from 'react';
import { Text, View } from 'react-native';
export default function Prizes() {
const { isLoaded, getPrizes } = usePrizes();
const [prizes, setPrizes] = useState<PrizeResource[]>([]);
useEffect(() => {
if (isLoaded) {
const fetchPrizes = async () => {
const result = await getPrizes();
setPrizes(result || []);
}
fetchPrizes();
}
}, [isLoaded, getPrizes]);
return (
<View>
{prizes.map((prize) => (
<View key={prize.uuid}>
<Text>{prize.name}</Text>
</View>
))}
</View>
)
}
On this page