In my app, rewarded ads only display once. When I return to the main menu or navigate to other pages and then go back to the rewarded ads page, the ads do not show again. I have to close the app and reopen it for the ads to display once more during that session.
Can you help me understand what’s happening and how to fix this issue?
import React, { useState, useEffect, useContext } from 'react';
import themeContext from '../themeContext';
import {View, Button, Text, FlatList, StyleSheet, Pressable, TouchableOpacity, ActivityIndicator} from 'react-native'
import {firebase} from '../../config';
import { BannerAd, BannerAdSize, RewardedAd, RewardedAdEventType, } from 'react-native-google-mobile-ads';
const rewarded = RewardedAd.createForAdRequest("ca-app-pub-3940256099942544/5224354917",);
const PageOne = ({ navigation }) =>{
useEffect(() => {
const unsubscribeLoaded = rewarded.addAdEventListener(RewardedAdEventType.LOADED, () => {
rewarded.show();
});
const unsubscribeEarned = rewarded.addAdEventListener(
RewardedAdEventType.EARNED_REWARD,
reward => {
console.log('User earned reward of ', reward);
},
);
// Start loading the rewarded ad straight away
rewarded.load();
// Unsubscribe from events on unmount
return () => {
unsubscribeLoaded();
unsubscribeEarned();
};
}, []);