fix: remove react forwardRef override

This commit is contained in:
Mark Lawlor
2022-05-31 12:18:31 +10:00
parent 2745669296
commit ecdcaa6408

View File

@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import * as React from "react";
import { styled } from "./styled";
import { StyledProps } from "./utils/styled";
@@ -6,26 +7,11 @@ export type StyledComponentProps<P> = StyledProps<P> & {
component: React.ComponentType<P>;
};
/**
* This might cause issues in the future, but we provide an override of forwardRef
* to provide better typing of our components
*/
declare module "react" {
// eslint-disable-next-line @typescript-eslint/ban-types
function forwardRef<T, P = {}>(
render: (props: P, ref: React.Ref<T>) => React.ReactElement | null
): React.ForwardRefExoticComponent<
React.PropsWithoutRef<P> & React.RefAttributes<T>
>;
}
function StyledComponentFunction<P>(
{ component, ...options }: StyledComponentProps<P>,
ref: React.ForwardedRef<unknown>
) {
const Component = styled(component);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return <Component {...(options as any)} ref={ref} />;
}
export const StyledComponent = React.forwardRef(StyledComponentFunction);
export const StyledComponent = React.forwardRef(
({ component, ...options }, ref) => {
const Component = styled(component);
return <Component {...(options as any)} ref={ref as any} />;
}
) as <T, P>(
props: StyledComponentProps<P> & React.RefAttributes<T>
) => React.ReactElement | null;