0

I have a pretty big javascript legacy code base of a WebApplication, which includes the presentation/data model/controller/connectivity. I'm trying to replace the presentation layer technology with ReactNative, while keep the existing data model/controller/connectivity parts. So the first question is, after I built the ReactNativeComponent where we have the UI layout defined, binding established, styles created... but I need to call some js functions from the legacy code. How can I require/import an existing js file (not a ReactNativeComponent) to one ReactNativeComponent and use it?

2 Answers 2

2

I've had this problem before too. Something I did, unable to find more elegant solutions, was to wrap my legacy code in a module.

Let's say this is foo.js

var Foo = (function() {
  var mod = {
    init: function() {
      // legacy code here...
    }
  }

  return mod;
})()

module.exports = Foo;

then in calling file:

import foo from './somewhere/foo';
foo.init();

I didn't love this approach, but it worked. Hopefully it can somewhat help.

Sign up to request clarification or add additional context in comments.

Comments

1

If they're purely js then you can import them normally. If they have anything to do with html/css/dom it will throw an error.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.