Created
March 21, 2024 16:40
-
-
Save LeandrodeLimaC/498552191829f10256715d80b3e39afb to your computer and use it in GitHub Desktop.
This updated version of ForwardRef was created to be used with generics typescript can't infer correctly the type of the reference in this scenario. The downside is that using this function, we will lose the dsiplayName property and some other stuff like defaultProperties. ref: https://fettblog.eu/typescript-react-generic-forward-refs/#option-3%…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This updated version of ForwardRef was created to be used with generics | |
* typescript can't infer correctly the type of the reference in this scenario. | |
* | |
* The downside is that using this function, we will lose the dsiplayName property | |
* and some other stuff like defaultProperties. | |
* | |
* ref: https://fettblog.eu/typescript-react-generic-forward-refs/#option-3%3A-augment-forwardref | |
*/ | |
export type FixedForwardRef = <T, P = {}>( | |
render: (props: P, ref: React.Ref<T>) => JSX.Element, | |
) => (props: P & React.RefAttributes<T>) => JSX.Element | |
export const forwardRef = reactForwardRef as FixedForwardRef |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment