Created
July 25, 2023 12:17
-
-
Save sunpietro/0625031ed6aa0aaa429d27c25f350c50 to your computer and use it in GitHub Desktop.
Fixed ForwardRef typing
This file contains hidden or 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
import React, { forwardRef } from "react"; | |
// Declare a type that works with generic components | |
type FixedForwardRef = <T, P = {}>( | |
render: (props: P, ref: React.Ref<T>) => React.ReactElement | |
) => (props: P & React.RefAttributes<T>) => React.ReactElement; | |
// Cast the old `forwardRef` to the new one | |
export const fixedForwardRef = | |
forwardRef as FixedForwardRef; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment