Skip to content

Instantly share code, notes, and snippets.

View HughParsons's full-sized avatar

Hugh Parsons HughParsons

View GitHub Profile
@HughParsons
HughParsons / forwardRefHOC.tsx
Created September 9, 2022 00:04
React HOC (higher order component) with forwardRef
import * as React from 'react'
export function HOC<T, P extends {}>(
Component: React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<T>>
): React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<T>> {
return React.forwardRef<T, P>(
function ComponentFromHOC(props, ref) {
return (
<Component {...props as React.PropsWithoutRef<P>} ref={ref} />
);