Skip to content

forwardRef display name attached to incorrect function #635

@joprice

Description

@joprice

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 https://github.com/Zaid-Ajaj/Feliz/blob/6841c9b150db7d73f1c9549ede07964949b5eaf0/Feliz/Internal.fs#L157.

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions