@@ -53,7 +53,7 @@ function LeafletProvider(props: { children: ComponentChildren }) {
5353 <p >Leaflet must be loaded on the client. No children will render</p >
5454 );
5555 }
56- const [ value, setValue] = useState <typeof Leaflet | null >(null );
56+ const value = useSignal <typeof Leaflet | null >(null )
5757 return (
5858 <>
5959 { /* Load Leaflet CSS */ }
@@ -65,7 +65,7 @@ function LeafletProvider(props: { children: ComponentChildren }) {
6565 />
6666 { /* Load Leaflet JS */ }
6767 <script
68- onLoad = { () => setValue ( window .L ) }
68+ onLoad = { () => value . value = window .L }
6969 src = " https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
7070 integrity = " sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
7171 crossorigin = " "
@@ -120,8 +120,9 @@ export default function MapIsland() {
120120``` tsx MapIsland.tsx
121121import * as Leaflet from " https://esm.sh/v135/@types/leaflet@1.9.4/index.d.ts" ;
122122import { IS_BROWSER } from " $fresh/runtime.ts" ;
123- import { useContext , useEffect , useState } from " preact/hooks" ;
123+ import { useContext , useEffect } from " preact/hooks" ;
124124import { ComponentChildren , createContext } from " preact" ;
125+ import { useSignal } from " @preact/signals" ;
125126
126127// Create a context to hold Leaflet data/functions
127128const LeafletContext = createContext <typeof Leaflet | null >(null );
@@ -131,7 +132,7 @@ function LeafletProvider(props: { children: ComponentChildren }) {
131132 if (! IS_BROWSER ) {
132133 return <p >Leaflet must be loaded on the client. No children will render</p >;
133134 }
134- const [ value, setValue] = useState <typeof Leaflet | null >(null );
135+ const value = useSignal <typeof Leaflet | null >(null );
135136 return (
136137 <>
137138 { /* Load Leaflet CSS */ }
@@ -143,7 +144,7 @@ function LeafletProvider(props: { children: ComponentChildren }) {
143144 />
144145 { /* Load Leaflet JS */ }
145146 <script
146- onLoad = { () => setValue ( window .L ) }
147+ onLoad = { () => value . value = window .L }
147148 src = " https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
148149 integrity = " sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
149150 crossorigin = " "
0 commit comments