Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

forwardRef display name attached to incorrect function #635

Open
joprice opened this issue Nov 7, 2024 · 0 comments
Open

forwardRef display name attached to incorrect function #635

joprice opened this issue Nov 7, 2024 · 0 comments

Comments

@joprice
Copy link

joprice commented Nov 7, 2024

When providing a name for a forwardRef, I see "Anonymous" as the display name. This seems to be caused by the extra wrapper function provided here

let forwardRefType = Interop.reactApi.forwardRef(Func<'props,IRefValue<'t>,ReactElement> (fun props ref -> render(props,ref)))
.

Shadowing the render function to displayName to be set on the wrapper function sets the name correctly:

  let forwardRefWithName
    (name: string)                                                                                                                 (render: ('props * IRefValue<'t> -> ReactElement))                                                                             : ('props * IRefValue<'t> -> ReactElement)
    =
    let render =
      System.Func<'props, IRefValue<'t>, ReactElement>(fun props ref -> render (props, ref))
    let forwardRefType = Interop.reactApi.forwardRef (render)
    render?displayName <- name
    fun (props, ref) ->
      let propsObj = props |> JsInterop.toPlainJsObj
      propsObj?ref <- ref
      Interop.reactApi.createElement (forwardRefType, propsObj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant