Below I'm defining some imports;
import users from './user';
import securities from './security';
import softwares from './software';
I want to be able to access them in the course of my file, but I can only access them dynamically if I do this:
const allCollections = {
users,
securities,
softwares
};
This way I can use it the way I need it:
function showImportDynamically(nameOfImportWanted) {
console.log(allCollections[nameOfImportWanted]);
}
Can you do this without resorting to creating a Object()
containing all?
I tried using global.users, but it did not work. I tried to take a look at the documentation so if I did import './users'
it would stay in memory but I could not capture it. Below the ./users
file as an example:
const users = {
fields: {
state: {},
city: {},
name: {}
}
};
export default users;