question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

  1. Make a method on native side with nullable boolean input parameter;
  2. Make a call from JS side and pass null;
  3. 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:closed
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

2reactions
niparxcommented, Apr 2, 2019

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?

1reaction
niparxcommented, Aug 2, 2019

Why it is not a bug? Please, comment at least

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found