Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggest Using Empty Array Instead of Undefined in dispatchViewManagerCommand #394

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

munhyok
Copy link

@munhyok munhyok commented Nov 10, 2024

Hello,
@ammarahm-ed

Screenshot_1731261167

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 according to its type definition. Therefore, I believe that using an empty array [] instead of undefined might be a more suitable approach.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant