React application for a project.
Today’s task: Passing configuration to a lazy loaded module in react.
There has to be a better way, but for now this will have to do.
main.js
const module = await import('./Modules/routes')
.then(routes => {
routes.default.configure(MYCONFIGURATION);
return routes;
});
Modules/routes.js
import { configure as configureApi } from './Data/api';
....
class AuthenticationRoutes extends Component {
/**
* Configure
* params MYCONFIGURATION
*/
static configure(MYCONFIGURATION) {
configureApi(MYCONFIGURATION)
}
......... other code
}
Data/api.js
export let MY_PARAMS;
export const configure = (params) => {
MY_PARAMS = params;
}