Explore Library
Code Quiz

Returning Values From a Native Module

Spot why this bridged native module method can't hand a value back to JavaScript.

Codejava
public class CalcModule extends ReactContextBaseJavaModule {
  CalcModule(ReactApplicationContext ctx) { super(ctx); }

  @Override
  public String getName() {
    return "CalcModule";
  }

  @ReactMethod
  public int add(int a, int b) {
    return a + b;
  }
}

// JS side:
// const sum = await NativeModules.CalcModule.add(2, 3);
// console.log(sum); // expects 5

Why will the JS call never receive the sum from this native module?