Unable to pass NULL value from JS side to native for primitive types
See original GitHub issue🐛 Bug Report
I need to pass a primitive type from JS to native side (ObjectiveC/Java). One of requirements: parameter value can be null. But I am not able to do that. I will show all that with boolean, but same problem exists for integer/double types as well.
To Reproduce
- Make a method on native side with nullable boolean input parameter;
- Make a call from JS side and pass
null
; - You’ll get a crash;
Expected Behavior
null
value is passed to native side (ObjectiveC/Java)
Code Example
JS side:
myFoo() {
return some_module.myFoo(null);
}
Java side:
@ReactMethod
public void doFoo(@Nullable final Boolean myValue) {
Log.d("my_app", "myValue: " + myValue);
}
ObjectiveC side:
RCT_REMAP_METHOD(doFoo, withMyValue:(nullable NSNumber*)myValue) {
NSLog(@"myValue: %@", myValue);
}
Environment
Environment: OS: macOS High Sierra 10.13.5 Node: 11.10.0 Yarn: 1.13.0 npm: 6.7.0 Watchman: 4.9.0 Xcode: Xcode 9.3.1 Build version 9E501 Android Studio: 3.2 AI-181.5540.7.32.5056338
Packages: (wanted => installed) react: 16.3.1 => 16.3.1 react-native: git+ssh://git@github.com:FATMAP/react-native.git#0.55.4-patched-default-location => 0.55.4
Issue Analytics
- State:
- Created 4 years ago
- Comments:8
Top Results From Across the Web
How can I pass null from react native to java when I develop a ...
So I write a function which can get null as a paramater in React Native and try to handle it in Java. React...
Read more >null - JavaScript - MDN Web Docs - Mozilla
The null value represents the intentional absence of any object value. It is one of JavaScript's primitive values and is treated as falsy...
Read more >Using nullability in GraphQL
When you try to return a null value in a resolver for a non-null field, the null result bubbles up to the nearest...
Read more >Handling a Null Response from an API
I've been working with React Native lately, which uses the Fetch API for asynchronously fetching data from web services.
Read more >Explaining Value vs. Reference in Javascript - codeburst
If a primitive type is assigned to a variable, we can think of that variable as containing the primitive value. var x =...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I was unable to find any information, why it is implemented in such way neither in issues list here in github repo, neither in stackoverflow or similar.
Can anyone give some notes about this?
Why it is not a bug? Please, comment at least