I wanna use Leaflet with NextJS(typescript).
But Leaflet dose not supported SSR. So, I use react-leaflet-univarsal.
Then, I custom Marker Component of Leaflet. So, I wanna use Leaflet.Icon.
I tried 2 things.
if(process.browser){}
This is not found window.
- use dynamic import with
next/dynamic
let iconPerson: any;
const DynamicComponent = dynamic(
() =>
import('leaflet').then(L => {
iconPerson = (L as any).Icon.extend({
options: {
iconUrl: '/images/icon1.jpg',
iconRetinaUrl: '/images/icon1.jpg',
iconSize: new (L as any).Point(60, 75),
className: 'leaflet-div-icon',
},
});
}) as any,
{ ssr: false },
);
....
<Marker icon={iconPerson}>
This is printed. > Cannot read property 'createIcon' of undefined
Is the way use L.icon with NextJS?