Hooks
usePoints
Home
Getting Started
Hooks
usePoints
The usePoints hook provides a way to get the current user’s points and to add points to the current user.
Usage
Get Points
import { usePoints } from '@useawards/useaward-expo';
import { useEffect, useState } from 'react';
import { Text, View } from 'react-native';
export default function Points() {
const { isLoaded, getPoints } = usePoints();
const [points, setPoints] = useState<number>([]);
useEffect(() => {
if (isLoaded) {
const fetchPoints = async () => {
const points = await getPoints();
setPoints(points);
}
fetchPoints();
}
}, [isLoaded, getPoints]);
return (
<View>
{points ?? 0}
</View>
)
}
Add Points
import { usePoints } from '@useawards/useaward-expo';
import { useEffect, useState } from 'react';
import { TouchableOpacity, Text, View } from 'react-native';
export default function Points() {
const { addPoints } = usePoints();
const handleAddPoints = async () => {
await addPoints(100, "Some reason"); // reason can be empty or null
}
return (
<View>
<TouchableOpacity onPress={handleAddPoints}>
<Text>Add Points</Text>
</TouchableOpacity>
</View>
)
}
On this page