Skip to content

Commit 64f4467

Browse files
committed
Remove useSessionStorage from experimental package
1 parent 58f07da commit 64f4467

File tree

1 file changed

+0
-43
lines changed

1 file changed

+0
-43
lines changed

index.js

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,6 @@ function throttle(cb, ms) {
4040
};
4141
}
4242

43-
function getEnvironment() {
44-
const isDOM =
45-
typeof window !== "undefined" &&
46-
window.document &&
47-
window.document.documentElement;
48-
49-
return isDOM ? "browser" : "server";
50-
}
51-
5243
export function useBattery() {
5344
const [state, setState] = React.useState({
5445
supported: true,
@@ -1373,40 +1364,6 @@ export function useRenderInfo(name = "Unknown") {
13731364
}
13741365
}
13751366

1376-
export function useSessionStorage(key, initialValue) {
1377-
if (getEnvironment() === "server") {
1378-
throw Error("useSessionStorage is a client-side only hook.");
1379-
}
1380-
1381-
const readValue = React.useCallback(() => {
1382-
try {
1383-
const item = window.sessionStorage.getItem(key);
1384-
return item ? JSON.parse(item) : initialValue;
1385-
} catch (error) {
1386-
console.warn(error);
1387-
return initialValue;
1388-
}
1389-
}, [key, initialValue]);
1390-
1391-
const [localState, setLocalState] = React.useState(readValue);
1392-
1393-
const handleSetState = React.useCallback(
1394-
(value) => {
1395-
try {
1396-
const nextState =
1397-
typeof value === "function" ? value(localState) : value;
1398-
window.sessionStorage.setItem(key, JSON.stringify(nextState));
1399-
setLocalState(nextState);
1400-
} catch (e) {
1401-
console.warn(e);
1402-
}
1403-
},
1404-
[key, localState]
1405-
);
1406-
1407-
return [localState, handleSetState];
1408-
}
1409-
14101367
export function useScript(src, options = {}) {
14111368
const [status, setStatus] = React.useState(() => {
14121369
if (!src) {

0 commit comments

Comments
 (0)