Reputation: 1630
I want to create a library file where I pass in a value and it returns an object that calls a created instance of localforage.
EDITED: simplified code still doesn't work
export default function(walkId) {
var store = localforage.createInstance({
name: walkId
});
var tilesDb = {
test: 'val'
};
return tilesDb;
}
and I import it like this:
import getTilesDb from './tilesDb';
but when I call it:
let tilesDB = getTilesDb(someIdhere);
I get an error TypeError: Object(...) is not a function
What am I doing wrong? Why can't I call my function?
Upvotes: 2
Views: 4446
Reputation: 8856
You cannot export an undefined variable. In the way you have written your code, getTitlesDb
is not defined yet.
There are two possible solutions. The first one is to name your function on the same line as the export
statement.
export default function getTilesDb(walkId) { ... }
The second one is to declare the function as a variable and then export the variable.
const getTilesDb = function(walkId) { ... }
export default getTilesDb;
Upvotes: 3