When using hooks adding parameters causes infinite rendering loop #54
Comments
const {} = useRewardedAd(UNITID, {
requestOptions
}); |
@wjaykim you missed on his first example. const {} = useRewardedAd(UNITID, {
loadOnMounted: false,
}); This puts the app in loop is there anything else to be noted ?
|
Currently I am investigating why this happens. Meanwhile, there is temporary solution for this. Declare your options outside of react component, or memoize your options like const hookOptions: FullScreenAdOptions = useMemo(
() => ({
loadOnDismissed: true,
requestOptions: {
requestNonPersonalizedAdsOnly: true,
},
}),
[]
); then infinite loop will not happen. |
@wjaykim how about we put the memo in the library where we are loading the config itself so it doesn't go in render loop ? |
@ShivamJoker Yes, I'll try that. |
Found that this issue comes from comparing options object with useEffect hook: https://stackoverflow.com/questions/54095994/react-useeffect-comparing-objects Ended up using https://github.com/kentcdodds/use-deep-compare-effect internally. Changes will available in next version. |
Fixes infinite render loop caused by comparing object with useEffect hook. Change to use [use-deep-compare-effect](https://github.com/kentcdodds/use-deep-compare-effect) internally. Refs: #54
Interesting findings :) Glad that you figured it |
I am using v1.2.1 and get the same response on IOS and Android. When using hooks like useRewardedAd, if I include parameters (doesnt seem to matter which ones, though my goal was to use requestNonPersonalizedAdsOnly) then the app goes into an infinite rendering loop. Below is an example setting almost all of the parameters, but I also just tried the requestNonPersonalizedAdsOnly one and got the same result.
const op = { loadOnMounted: true, showOnLoaded: false, loadOnDismissed:true, requestOptions: { requestNonPersonalizedAdsOnly: true}}; const { adLoadError, adLoaded, show, load, reward, adPresented, adDismissed } = useRewardedAd(TestIds.REWARDED, op);
Or this code:
const requestOptions = { requestNonPersonalizedAdsOnly: true, }; const { adLoadError, adLoaded, show, load, reward, adPresented, adDismissed } = useRewardedAd(TestIds.REWARDED, requestOptions);
The text was updated successfully, but these errors were encountered: