If I use a string literal in the require
it works fine, if I use a string variable it errors with:
Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
This is my code:
type FlagIconProps = {
twoCharLocationCode: string,
widthPx?: string
}
const FlagIcon = ({ twoCharLocationCode, widthPx = '32px' }: FlagIconProps) => {
const fileName2 = './us.svg'
// hard coded filename WORKS
// const flagIconImg: string = require('./us.svg').default
// using a variable in the require casues: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
const flagIconImg: string = require(fileName2).default
return (
<img
src={flagIconImg}
className="flag-icon"
alt="flag-icon"
width={widthPx}
/>
)
}
export default FlagIcon
But I'm not using useEffect anywhere in the app so I really don't understand what to do to fix this. Using variables is fairly fundamental to coding lol
Appreciate any help!