Reputation: 173
Is it possible to make use of common js modules with react-native? The use case is sharing logic between a mobile and web version of a react project.
Upvotes: 10
Views: 8115
Reputation: 1317
Ok, I'm new to this too but I think I've figured out how to include js code. I didn't have to add anything to the standard react native installation.
Create a Library of code:
//library.js
exports.foo = function() {
//Do stuff here
return "Here";
}
Import into another js file:
var lib = require("./library.js");
var myString = lib.foo();
I found the info from this blog post:
http://0fps.net/2013/01/22/commonjs-why-and-how/
Upvotes: 11