Access static variable from another class in React-Native app?
I think you also forgot the this keyword for returning the static "currentUser" field:
class User {
constructor() {}
static currentUser = {
uname: 'xxx',
firstname: 'first',
lastname: 'last'
};
static getCurrentUser() {
return this.currentUser;
}
}
console.log(User.getCurrentUser());
You are mixing import
/ export
styles. You should either change your import to
var User = require('./User').default
or
import User from './User'
Or change your export:
module.exports = User