react-native-admob-native-ads
react-native-admob-native-ads copied to clipboard
Suggest using empty array instead of undefined in dispatchViewManagerCommand
Hello, @ammarahm-ed
While working with UIManager.dispatchViewManagerCommand in React Native, I noticed an issue where passing undefined as the commandArgs parameter leads to an UnexpectedNativeTypeException.
From what I understand, this is because commandArgs is expected to be an optional Array
Problem Description:
Currently, the loadAd function passes undefined for commandArgs:
loadAd = () => { UIManager.dispatchViewManagerCommand( findNodeHandle(this.nativeAdRef), UIManager.getViewManagerConfig("RNGADNativeView").Commands.loadAd, undefined ); };
Suggested Change:
loadAd = () => { UIManager.dispatchViewManagerCommand( findNodeHandle(this.nativeAdRef), UIManager.getViewManagerConfig("RNGADNativeView").Commands.loadAd, [] // Using an empty array instead of undefined ); };
Reasoning for the Suggestion:
This approach can prevent the UnexpectedNativeTypeException that occurs when undefined is passed.
Aligning the parameter type with the expected definition might reduce potential errors and make the code safer.
I hope this suggestion can be helpful for the project. Please feel free to share any feedback or if further discussion is needed!
Thank you