Co2p Co2p - 3 months ago 7
React JSX Question

const arrow function can't access imports

Why is User not defined in the springboard function?

springboard is called

onEnter
in a React router Route.

import User from '/imports/api/user.js';

const springboard = (nextState, replace, callback) => {
console.log(User.get());
}


Snippet from User:

User = {
get: function() {
return Meteor.user() || {};
},
...
}

Answer

You have to export the object that you want to import:

export default {
  get: …

Note that the name of the exported object doesn't matter. You can give it any name, e.g., User when importing.

Comments