Skip to content

Commit

Permalink
chore(clerk-js,clerk-react): Share createContextAndHook
Browse files Browse the repository at this point in the history
  • Loading branch information
nikosdouvlis committed Oct 25, 2022
1 parent 262499e commit fb37054
Show file tree
Hide file tree
Showing 21 changed files with 31 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContextAndHook } from '@clerk/shared';
import React from 'react';

import { useDeepEqualMemo } from '../hooks';
import { createContextAndHook } from '../utils';
import { AppearanceCascade, parseAppearance, ParsedAppearance } from './parseAppearance';

type AppearanceContextValue = ParsedAppearance;
Expand Down
2 changes: 1 addition & 1 deletion packages/clerk-js/src/ui/elements/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import { Button, descriptors, Flex, Form as FormPrim, localizationKeys } from '../customizables';
import { useLoadingStatus } from '../hooks';
import { PropsOfComponent } from '../styledSystem';
import { createContextAndHook } from '../utils';
import { createContextAndHook } from '@clerk/shared';
import { useCardState } from './contexts';
import { FormControl } from './FormControl';

Expand Down
2 changes: 1 addition & 1 deletion packages/clerk-js/src/ui/elements/Menu.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { cloneElement, isValidElement, PropsWithChildren, useEffect, useRef } from 'react';

import { createContextAndHook } from '../../ui/utils';
import { createContextAndHook } from '@clerk/shared';
import { Button, Col } from '../customizables';
import { usePopover, UsePopoverReturn } from '../hooks';
import { animations, PropsOfComponent } from '../styledSystem';
Expand Down
3 changes: 2 additions & 1 deletion packages/clerk-js/src/ui/elements/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createContextAndHook } from '@clerk/shared';
import React from 'react';

import { useNavigateToFlowStart } from '../components/UserProfile/NavigateToFlowStartButton';
Expand All @@ -15,7 +16,7 @@ import { ElementDescriptor, ElementId } from '../customizables/elementDescriptor
import { useNavigate, usePopover, useSafeLayoutEffect } from '../hooks';
import { Menu } from '../icons';
import { animations, mqu, PropsOfComponent } from '../styledSystem';
import { colors, createContextAndHook } from '../utils';
import { colors } from '../utils';

type NavbarContextValue = { isOpen: boolean; open: () => void; close: () => void };
export const [NavbarContext, useNavbarContext] = createContextAndHook<NavbarContextValue>('NavbarContext');
Expand Down
5 changes: 3 additions & 2 deletions packages/clerk-js/src/ui/elements/Select.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, { isValidElement, PropsWithChildren, useState } from 'react';
import { createContextAndHook } from '@clerk/shared';
import React, { PropsWithChildren, useState } from 'react';

import { usePopover, useSearchInput } from '../../ui/hooks';
import { Button, Flex, Icon, Text } from '../customizables';
import { Caret, MagnifyingGlass } from '../icons';
import { animations, common, PropsOfComponent, ThemableCssProp } from '../styledSystem';
import { colors, createContextAndHook } from '../utils';
import { colors } from '../utils';
import { InputWithIcon } from './InputWithIcon';

type UsePopoverReturn = ReturnType<typeof usePopover>;
Expand Down
3 changes: 2 additions & 1 deletion packages/clerk-js/src/ui/elements/Tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { createContextAndHook } from '@clerk/shared';
import React from 'react';

import { Button, Col, Flex } from '../customizables';
import { PropsOfComponent } from '../styledSystem';
import { createContextAndHook, getValidChildren } from '../utils';
import { getValidChildren } from '../utils';

type TabsContextValue = {
selectedIndex: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createContextAndHook } from '@clerk/shared';
import { ClerkAPIError } from '@clerk/types';
import React from 'react';

import { useLocalizations } from '../../customizables';
import { useSafeState } from '../../hooks';
import { createContextAndHook } from '../../utils';

type Status = 'idle' | 'loading' | 'error';
type Metadata = string | undefined;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { createContextAndHook } from '../../utils';
import { createContextAndHook } from '@clerk/shared';

type FlowMetadata = {
flow: 'signIn' | 'signUp' | 'userButton' | 'userProfile' | 'organizationProfile' | 'organizationSwitcher';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { createContextAndHook } from '../../utils';
import { createContextAndHook } from '@clerk/shared';

export type FormControlProps = {
/**
Expand Down
1 change: 0 additions & 1 deletion packages/clerk-js/src/ui/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * from './fromEntries';
export * from './containsAllOf';
export * from './createContextAndHook';
export * from './createInfiniteAccessProxy';
export * from './fastDeepMerge';
export * from './colors';
Expand Down
1 change: 1 addition & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
},
"dependencies": {
"@clerk/types": "^3.13.0",
"@clerk/shared": "^0.4.1",
"swr": "^1.3.0",
"tslib": "^2.3.1"
},
Expand Down
5 changes: 2 additions & 3 deletions packages/react/src/contexts/AuthContext.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { createContextAndHook } from '@clerk/shared';
import type { ActJWTClaim } from '@clerk/types';

import { makeContextAndHook } from '../utils/makeContextAndHook';

export const [AuthContext, useAuthContext] = makeContextAndHook<{
export const [AuthContext, useAuthContext] = createContextAndHook<{
userId: string | null | undefined;
sessionId: string | null | undefined;
actor: ActJWTClaim | null;
Expand Down
8 changes: 4 additions & 4 deletions packages/react/src/contexts/ClientContext.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createContextAndHook } from '@clerk/shared';
import { ClientResource } from '@clerk/types';
import React from 'react';

import { makeContextAndHook } from '../utils/makeContextAndHook';

/**
* @internal
*/
export const [ClientContext, useClientContext] = makeContextAndHook<ClientResource | undefined | null>('ClientContext');
export const [ClientContext, useClientContext] = createContextAndHook<ClientResource | undefined | null>(
'ClientContext',
);
5 changes: 3 additions & 2 deletions packages/react/src/contexts/IsomorphicClerkContext.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { createContextAndHook } from '@clerk/shared';

import IsomorphicClerk from '../isomorphicClerk';
import { makeContextAndHook } from '../utils/makeContextAndHook';

/**
* @internal
*/
export const [IsomorphicClerkContext, useIsomorphicClerkContext] =
makeContextAndHook<IsomorphicClerk>('IsomorphicClerkContext');
createContextAndHook<IsomorphicClerk>('IsomorphicClerkContext');
5 changes: 2 additions & 3 deletions packages/react/src/contexts/OrganizationContext.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { createContextAndHook } from '@clerk/shared';
import { OrganizationInvitationResource, OrganizationMembershipResource, OrganizationResource } from '@clerk/types';

import { makeContextAndHook } from '../utils/makeContextAndHook';

/**
* @internal
*/
export const [OrganizationContext, useOrganizationContext] = makeContextAndHook<{
export const [OrganizationContext, useOrganizationContext] = createContextAndHook<{
organization: OrganizationResource | null | undefined;
lastOrganizationInvitation: OrganizationInvitationResource | null | undefined;
lastOrganizationMember: OrganizationMembershipResource | null | undefined;
Expand Down
5 changes: 2 additions & 3 deletions packages/react/src/contexts/SessionContext.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { createContextAndHook } from '@clerk/shared';
import { ActiveSessionResource } from '@clerk/types';

import { makeContextAndHook } from '../utils/makeContextAndHook';

/**
* @internal
*/
export const [SessionContext, useSessionContext] = makeContextAndHook<ActiveSessionResource | null | undefined>(
export const [SessionContext, useSessionContext] = createContextAndHook<ActiveSessionResource | null | undefined>(
'SessionContext',
);
5 changes: 2 additions & 3 deletions packages/react/src/contexts/UserContext.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { createContextAndHook } from '@clerk/shared';
import { UserResource } from '@clerk/types';

import { makeContextAndHook } from '../utils/makeContextAndHook';

/**
* @internal
*/
export const [UserContext, useUserContext] = makeContextAndHook<UserResource | null | undefined>('UserContext');
export const [UserContext, useUserContext] = createContextAndHook<UserResource | null | undefined>('UserContext');
17 changes: 0 additions & 17 deletions packages/react/src/utils/makeContextAndHook.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/shared/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './createContextAndHook';
1 change: 1 addition & 0 deletions packages/shared/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './utils';
export * from './hooks';

0 comments on commit fb37054

Please sign in to comment.