mirror of
https://github.com/zhigang1992/nativewind.git
synced 2026-06-15 18:27:52 +08:00
fix: remove react forwardRef override
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user