#Separating types from js: React forwardRef

9 messages · Page 1 of 1 (latest)

terse burrow
#

...

normal sableBOT
#
OnkelTem#4669

Preview:```ts
import React, {
ComponentType,
forwardRef,
ForwardRefExoticComponent,
PropsWithoutRef,
RefAttributes,
} from "react"

// Variant 1: with forwardRef
namespace V1 {
const withFoo = <P extends JSX.IntrinsicAttributes>(
Component: ComponentType<P>
)
...```

terse burrow
#

I cannot understand why it's not working? I did everything properly, did I?

stuck blade
#

What's the goal of "separating the types from the JS"?

#

I don't see an obvious error there; but it's a fairly complex type so it might be easy to miss something minor.

normal sableBOT
#
OnkelTem#4669

Preview:```ts
import React, {ComponentType, forwardRef} from "react"

// Variant 1: with forwardRef
namespace V1 {
const withFoo = <P extends JSX.IntrinsicAttributes>(
Component: ComponentType<P>
) =>
forwardRef<HTMLFormElement, P>((props, ref) => {
return
...```

terse burrow
#

A bit more minimal version, where I just take the ReturnType of the library function forwardRef

#

I just don't see how an error could appear

#

Because in V1 I use forwardRef function generic, and in the V2 I do just_the_same