File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -1200,16 +1200,22 @@ export function useSessionStorage(key, initialValue) {
1200
1200
[ key , store ]
1201
1201
) ;
1202
1202
1203
+ const initialValueRef = useRef ( initialValue )
1204
+
1203
1205
React . useEffect ( ( ) => {
1204
1206
if (
1205
1207
getSessionStorageItem ( key ) === null &&
1206
1208
typeof initialValue !== "undefined"
1207
1209
) {
1208
- setSessionStorageItem ( key , initialValue ) ;
1210
+ setSessionStorageItem ( key , initialValueRef . current ) ;
1209
1211
}
1210
- } , [ key , initialValue ] ) ;
1212
+ } , [ key ] ) ;
1211
1213
1212
- return [ store ? JSON . parse ( store ) : initialValue , setState ] ;
1214
+ const result = useMemo ( ( ) => {
1215
+ return store ? JSON . parse ( store ) : initialValueRef . current
1216
+ } , [ store ] )
1217
+
1218
+ return [ result , setState ] ;
1213
1219
}
1214
1220
1215
1221
export function useSet ( values ) {
You can’t perform that action at this time.
0 commit comments