support Option ref type in forwardRef
Opened this issue · 2 comments
evbo commented
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 commented
Note to self, this is documented at https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/index.d.ts#L543
shadaj commented
This is going to be a breaking change, so unfortunately we may have to wait until v0.8.0.