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

support Option ref type in forwardRef #566

Open
evbo opened this issue Apr 25, 2022 · 2 comments
Open

support Option ref type in forwardRef #566

evbo opened this issue Apr 25, 2022 · 2 comments
Labels
Milestone

Comments

@evbo
Copy link

evbo commented Apr 25, 2022

Hi, some very reputable JS libraries rely on forwardRef being able to take an optional ref, for instance here:
https://react-table.tanstack.com/docs/examples/row-selection

So is it possible to support Option[ReactRef[_]] types?

The only way I could get this code equivalent in slinky was to hack with a null check:

val component = React.forwardRef(FunctionalComponent(
    fn = (props: RowSelectorProps, tableRef: /*TODO: needs to be Option Type*/ReactRef[js.Any]) => {
      val defaultRef = useRef[js.Any](null)

      // TODO: faking it for now...
      val resolvedRef = if (tableRef != null) tableRef else defaultRef

      useEffect(
        () => {
          resolvedRef.current.asInstanceOf[js.Dynamic].indeterminate = props.indeterminate
        },
        Seq(resolvedRef, props.indeterminate)
      )

      println(s"checked: ${props.checked}, ind: ${props.indeterminate}, table: ${tableRef}")

      div(
        input(
          `type` := "checkbox",
          checked := props.checked,
          onChange := props.onChange,
          ref := resolvedRef,
          style := props.style
        )
      )
    }
  ))
@shadaj
Copy link
Owner

shadaj commented Apr 30, 2022

@shadaj shadaj added the bug label Apr 30, 2022
@shadaj shadaj added this to the v0.8.0 milestone Apr 30, 2022
@shadaj
Copy link
Owner

shadaj commented Apr 30, 2022

This is going to be a breaking change, so unfortunately we may have to wait until v0.8.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants