Gagan
Gagan

Reputation: 5656

Undefined is not a function whenever I try to create a new react function

I installed react-native-installed-packages. It is working fine out of the box. However I want to modify it by adding some extra methods that I can use in my JS. Here is what I have done.

enter image description here

As you can see from the image above, I have added a new public method, but whenever I am trying to call it from JS , I get the following error

undefined is not a function (evaluating 'InstalledApps.removeApp(myappPackageID)')

Edit 1

This is how I am using it in my JS

First I am importing the module

var InstalledApps = require('react-native-installed-packages');

and then I am calling the function as such

let val = InstalledApps.removeApp(myappPackageID);

My RNInstalledAppsPackage looks like this

Edit 2

package com.reactlibrary;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.bridge.JavaScriptModule;
public class RNInstalledAppsPackage implements ReactPackage {
    @Override
    public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
      return Arrays.<NativeModule>asList(new RNInstalledAppsModule(reactContext));
    }

    @Override
    public List<Class<? extends JavaScriptModule>> createJSModules() {
      return Collections.emptyList();
    }

    @Override
    public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
      return Collections.emptyList();
    }
}

Can you please suggest what I am doing wrong here ? Thanks

Upvotes: 1

Views: 836

Answers (1)

Kunal
Kunal

Reputation: 604

Add your method in JS interface as well and try rebuild. JS interface file is "rn-installed-apps/index.js". This is the url : https://github.com/jstokes/rn-installed-apps/blob/master/index.js

Upvotes: 1

Related Questions