I'm using react, typescript. This is part of my code using react lazy.
import {lazy} from 'react';
const LAZY_PANELS = {};
const PANELS = {
'home': () => import('./home'),
'settings': () => import('./settings'),
'profile': () => import('./profile'),
}
for (const route of Object.keys(PANELS)) {
LAZY_PANELS[PANELS[route]] = lazy(PANELS[route]);
}
I'm using PANELS object to render my components and it's working fine. after adding @typescript-eslint/promise-function-async
to my eslint rules i needed to change my code like this:
import {lazy} from 'react';
const LAZY_PANELS = {};
const PANELS = {
'home': async () => import('./home'),
'settings': async () => import('./settings'),
'profile': async () => import('./profile'),
}
for (const route of Object.keys(PANELS)) {
LAZY_PANELS[PANELS[route]] = lazy(PANELS[route]);
}
I did it and everything was OK but after creating a new build in deployed version lazy components are not in correct order. PANELS.home
is equal to profile component and PANELS.profile
is equal to home component.
I know that if I remove asyncs and disable that rule here or even use checkArrowFunctions
option to ignore arrow functions it's gonna be OK but i rather to know the reason why it's happening and maybe solve it in a better way.