Skip to content

Instantly share code, notes, and snippets.

@viclafouch
Created August 2, 2023 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viclafouch/58464ad24d48205381bfb11625aa4bc3 to your computer and use it in GitHub Desktop.
Save viclafouch/58464ad24d48205381bfb11625aa4bc3 to your computer and use it in GitHub Desktop.
Redesign of forwardRef in TS
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.ReactNode
) => (props: P & React.RefAttributes<T>) => React.ReactNode;
// 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