Skip to content

Instantly share code, notes, and snippets.

@conor909
Last active July 25, 2023 15:06
Show Gist options
  • Save conor909/65d0028eded39d41085f9a9e9d37f3a9 to your computer and use it in GitHub Desktop.
Save conor909/65d0028eded39d41085f9a9e9d37f3a9 to your computer and use it in GitHub Desktop.
react TS forwardRef
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