Suggest using empty array instead of undefined in dispatchViewManagerCommand #394
Open
munhyok wants to merge 1 commit into
Open
Suggest using empty array instead of undefined in dispatchViewManagerCommand
#394munhyok wants to merge 1 commit into
munhyok wants to merge 1 commit into
Conversation
Author
|
There is an actual case where this issue was resolved. Please merge it! |
Contributor
|
My app crashed whenever I showed ads in never RN versions. This PR fixed it 🙌 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 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