Skip to content

Commit

Permalink
chore: migrate useIsMounted to usehooks-ts
Browse files Browse the repository at this point in the history
  • Loading branch information
bigint committed May 31, 2023
1 parent 8c3609a commit cc1e8cd
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 59 deletions.
7 changes: 3 additions & 4 deletions apps/web/src/components/Common/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ import type { FC, ReactNode } from 'react';
import { Toaster } from 'react-hot-toast';
import { CHAIN_ID } from 'src/constants';
import { useAppPersistStore, useAppStore } from 'src/store/app';
import { useUpdateEffect } from 'usehooks-ts';
import { useIsMounted, useUpdateEffect } from 'usehooks-ts';
import { useAccount, useDisconnect, useNetwork } from 'wagmi';

import GlobalModals from '../Shared/GlobalModals';
import Loading from '../Shared/Loading';
import Navbar from '../Shared/Navbar';
import useIsMounted from '../utils/hooks/useIsMounted';
import { useDisconnectXmtp } from '../utils/hooks/useXmtpClient';

interface LayoutProps {
Expand All @@ -32,7 +31,7 @@ const Layout: FC<LayoutProps> = ({ children }) => {
const profileId = useAppPersistStore((state) => state.profileId);
const setProfileId = useAppPersistStore((state) => state.setProfileId);

const { mounted } = useIsMounted();
const isMounted = useIsMounted();
const { address } = useAccount();
const { chain } = useNetwork();
const { disconnect } = useDisconnect();
Expand Down Expand Up @@ -90,7 +89,7 @@ const Layout: FC<LayoutProps> = ({ children }) => {
validateAuthentication();
}, [address, chain, disconnect, profileId]);

if (loading || !mounted) {
if (loading || !isMounted()) {
return <Loading />;
}

Expand Down
3 changes: 1 addition & 2 deletions apps/web/src/components/Messages/Composer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import useWindowSize from '@components/utils/hooks/useWindowSize';
import { ArrowRightIcon, PhotographIcon } from '@heroicons/react/outline';
import { XIcon } from '@heroicons/react/solid';
import { Leafwatch } from '@lib/leafwatch';
Expand All @@ -18,7 +17,7 @@ import {
import { useMessagePersistStore } from 'src/store/message';
import { MESSAGES } from 'src/tracking';
import { Button, Input, Spinner } from 'ui';
import { useUpdateEffect } from 'usehooks-ts';
import { useUpdateEffect, useWindowSize } from 'usehooks-ts';
import type {
Attachment as TAttachment,
RemoteAttachment
Expand Down
10 changes: 5 additions & 5 deletions apps/web/src/components/Shared/Login/WalletSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import SwitchNetwork from '@components/Shared/SwitchNetwork';
import useIsMounted from '@components/utils/hooks/useIsMounted';
import { KeyIcon } from '@heroicons/react/outline';
import { XCircleIcon } from '@heroicons/react/solid';
import errorToast from '@lib/errorToast';
Expand All @@ -21,6 +20,7 @@ import { useAppPersistStore, useAppStore } from 'src/store/app';
import { useAuthStore } from 'src/store/auth';
import { AUTH } from 'src/tracking';
import { Button, Spinner } from 'ui';
import { useIsMounted } from 'usehooks-ts';
import type { Connector } from 'wagmi';
import {
useAccount,
Expand Down Expand Up @@ -50,7 +50,7 @@ const WalletSelector: FC<WalletSelectorProps> = ({
errorToast(error);
};

const { mounted } = useIsMounted();
const isMounted = useIsMounted();
const { chain } = useNetwork();
const { connectors, error, connectAsync } = useConnect({ chainId: CHAIN_ID });
const { disconnect } = useDisconnect();
Expand Down Expand Up @@ -198,18 +198,18 @@ const WalletSelector: FC<WalletSelectorProps> = ({
)}
onClick={() => onConnect(connector)}
disabled={
mounted
isMounted()
? !connector.ready || connector.id === activeConnector?.id
: false
}
>
<span>
{mounted
{isMounted()
? connector.id === 'injected'
? t`Browser Wallet`
: getWalletDetails(connector.name).name
: getWalletDetails(connector.name).name}
{mounted ? !connector.ready && ' (unsupported)' : ''}
{isMounted() ? !connector.ready && ' (unsupported)' : ''}
</span>
<img
src={getWalletDetails(connector.name).logo}
Expand Down
13 changes: 0 additions & 13 deletions apps/web/src/components/utils/hooks/useIsMounted.tsx

This file was deleted.

35 changes: 0 additions & 35 deletions apps/web/src/components/utils/hooks/useWindowSize.tsx

This file was deleted.

0 comments on commit cc1e8cd

Please sign in to comment.