Skip to content

Commit

Permalink
remove usehooks-ts (#2436)
Browse files Browse the repository at this point in the history
we only use one hook from package,
& usehooks-ts is one of the packages blocking react 19
  • Loading branch information
serprex authored Jan 13, 2025
1 parent 21652d2 commit b1482ac
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 30 deletions.
Empty file modified generate-protos.sh
100644 → 100755
Empty file.
6 changes: 3 additions & 3 deletions ui/app/mirror-logs/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { ListMirrorNamesResponse } from '@/grpc_generated/route';
import { ProgressCircle } from '@/lib/ProgressCircle';
import ReactSelect from 'react-select';
import useSWR from 'swr';
import { useLocalStorage } from 'usehooks-ts';
import { fetcher } from '../utils/swr';
import useLocalStorage from '../utils/useLocalStorage';

export default function LogsView() {
const [mirrorName, setMirrorName] = useLocalStorage<string>(
const [mirrorName, setMirrorName] = useLocalStorage(
'peerdbMirrorNameFilterForLogs',
''
);
const [logLevel, setLogLevel] = useLocalStorage<string>(
const [logLevel, setLogLevel] = useLocalStorage(
'peerdbLogTypeFilterForLogs',
'all'
);
Expand Down
2 changes: 1 addition & 1 deletion ui/app/mirrors/[mirrorId]/cdc.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use client';
import useLocalStorage from '@/app/utils/useLocalStorage';
import { MirrorStatusResponse } from '@/grpc_generated/route';
import { Label } from '@/lib/Label';
import { ProgressCircle } from '@/lib/ProgressCircle';
import { Tab, TabGroup, TabList, TabPanel, TabPanels } from '@tremor/react';
import { useEffect, useState } from 'react';
import { useLocalStorage } from 'usehooks-ts';
import CdcDetails from './cdcDetails';
import { SnapshotStatusTable } from './snapshot';

Expand Down
2 changes: 1 addition & 1 deletion ui/app/peers/[peerName]/lagGraph.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';
import SelectTheme from '@/app/styles/select';
import { TimeAggregateTypes, timeOptions } from '@/app/utils/graph';
import useLocalStorage from '@/app/utils/useLocalStorage';
import {
GetSlotLagHistoryRequest,
GetSlotLagHistoryResponse,
Expand All @@ -11,7 +12,6 @@ import { LineChart } from '@tremor/react';
import moment from 'moment';
import { useCallback, useEffect, useState } from 'react';
import ReactSelect from 'react-select';
import { useLocalStorage } from 'usehooks-ts';
import { getSlotData } from './helpers';

type LagGraphProps = {
Expand Down
20 changes: 20 additions & 0 deletions ui/app/utils/useLocalStorage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Dispatch, SetStateAction, useEffect, useState } from 'react';

export default function useLocalStorage<T>(
key: string,
defaultValue: T
): [T, Dispatch<SetStateAction<T>>] {
const [value, setValue] = useState(() => {
if (typeof localStorage === 'undefined') return defaultValue;
const json = localStorage.getItem(key);
if (!json) return defaultValue;
return JSON.parse(json);
});

useEffect(() => {
if (typeof localStorage !== 'undefined')
localStorage.setItem(key, JSON.stringify(value));
}, [key, value]);

return [value, setValue];
}
2 changes: 1 addition & 1 deletion ui/components/SidebarComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';

import { fetcher } from '@/app/utils/swr';
import useLocalStorage from '@/app/utils/useLocalStorage';
import Logout from '@/components/Logout';
import { PeerDBVersionResponse } from '@/grpc_generated/route';
import { BrandLogo } from '@/lib/BrandLogo';
Expand All @@ -12,7 +13,6 @@ import { Sidebar, SidebarItem } from '@/lib/Sidebar';
import { SessionProvider } from 'next-auth/react';
import Link from 'next/link';
import useSWR from 'swr';
import { useLocalStorage } from 'usehooks-ts';

const centerFlexStyle = {
display: 'flex',
Expand Down
2 changes: 1 addition & 1 deletion ui/components/TimeComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use client';
import useLocalStorage from '@/app/utils/useLocalStorage';
import { Label } from '@/lib/Label';
import { ProgressCircle } from '@/lib/ProgressCircle';
import moment from 'moment-timezone';
import { useEffect, useState } from 'react';
import { useLocalStorage } from 'usehooks-ts';

const TimeLabel = ({
timeVal,
Expand Down
22 changes: 0 additions & 22 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"react-toastify": "^11.0.2",
"styled-components": "^6.1.13",
"swr": "^2.2.5",
"usehooks-ts": "^3.1.0",
"zod": "^3.23.8"
},
"devDependencies": {
Expand Down

0 comments on commit b1482ac

Please sign in to comment.