Skip to content

Commit

Permalink
fix(ui): update environment context typing (#139)
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Schultz <[email protected]>
  • Loading branch information
schultzp2020 committed Jun 20, 2023
1 parent 164a1af commit d8db253
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion apps/website/src/lib/providers/environment-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,27 @@

import Link from '@docusaurus/Link';
import React, { memo, type ComponentProps } from 'react';
import { EnvironmentContext } from 'ui/contexts';
import { EnvironmentContext, type ImageProps } from 'ui/contexts';

const LinkWrapper = memo((props: ComponentProps<'a'>) => {
const { href, ...rest } = props;

return <Link {...rest} to={href} />;
});

const ImageWrapper = memo((props: ImageProps) => (
// eslint-disable-next-line jsx-a11y/alt-text
<img {...props} />
));

export function EnvironmentProvider({ children }: { children: React.ReactNode }): JSX.Element {
return (
<EnvironmentContext.Provider
// LinkWrapper has been memoized to avoid unnecessary re-renders
// eslint-disable-next-line react/jsx-no-constructed-context-values
value={{
Link: LinkWrapper,
Image: ImageWrapper,
}}
>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// ImageProps line complains
/* eslint-disable @typescript-eslint/indent */

import React, { createContext, type ComponentProps } from 'react';
import React, { createContext, type ComponentProps, type FunctionComponent } from 'react';

export type LinkProps = Omit<ComponentProps<'a'>, 'href'> &
Pick<Required<ComponentProps<'a'>>, 'href'>;
Expand All @@ -27,8 +27,8 @@ export type ImageProps = Omit<ComponentProps<'img'>, 'src' | 'alt'> &
Pick<Required<ComponentProps<'img'>>, 'src' | 'alt'>;

export const EnvironmentContext = createContext<{
Link?: React.FunctionComponent<ComponentProps<'a'>>;
Image?: React.FunctionComponent<ImageProps>;
Link: FunctionComponent<ComponentProps<'a'>>;
Image: FunctionComponent<ImageProps>;
}>({
// children will always exist
// eslint-disable-next-line jsx-a11y/anchor-has-content
Expand Down

0 comments on commit d8db253

Please sign in to comment.