Skip to content

Commit

Permalink
Add ChildrenProps reusable type
Browse files Browse the repository at this point in the history
  • Loading branch information
blazejkustra committed Oct 16, 2023
1 parent d4c7fd5 commit 52e804e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
12 changes: 3 additions & 9 deletions src/components/ComposeProviders.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import React, {ComponentType, ReactNode} from 'react';
import ChildrenProps from '../types/utils/ChildrenProps';

type ComponentProps = {
children: ReactNode;
};

type ComposeProvidersProps = {
type ComposeProvidersProps = ChildrenProps & {
/** Provider components go here */
components: Array<ComponentType<ComponentProps>>;

/** Rendered child component */
children: ReactNode;
components: Array<ComponentType<ChildrenProps>>;
};

function ComposeProviders(props: ComposeProvidersProps): ReactNode {
Expand Down
8 changes: 2 additions & 6 deletions src/components/createOnyxContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@ import {withOnyx} from 'react-native-onyx';
import Str from 'expensify-common/lib/str';
import getComponentDisplayName from '../libs/getComponentDisplayName';
import {OnyxCollectionKey, OnyxKey, OnyxKeyValue, OnyxValues} from '../ONYXKEYS';
import ChildrenProps from '../types/utils/ChildrenProps';

type OnyxKeys = (OnyxKey | OnyxCollectionKey) & keyof OnyxValues;

// Provider types
type ProviderOnyxProps<TOnyxKey extends OnyxKeys> = Record<TOnyxKey, OnyxKeyValue<TOnyxKey>>;

type ProviderProps = {
/** Rendered child component */
children: ReactNode;
};

type ProviderPropsWithOnyx<TOnyxKey extends OnyxKeys> = ProviderProps & ProviderOnyxProps<TOnyxKey>;
type ProviderPropsWithOnyx<TOnyxKey extends OnyxKeys> = ChildrenProps & ProviderOnyxProps<TOnyxKey>;

// withOnyxKey types
type WithOnyxKeyProps<TOnyxKey extends OnyxKeys, TNewOnyxKey extends string, TTransformedValue> = {
Expand Down
8 changes: 8 additions & 0 deletions src/types/utils/ChildrenProps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type {ReactNode} from 'react';

type ChildrenProps = {
/** Rendered child component */
children: ReactNode;
};

export default ChildrenProps;

0 comments on commit 52e804e

Please sign in to comment.