as prop of an ElementComponent
#1222
NicholasBoll
started this conversation in
General
Replies: 1 comment
-
FunctionComponent<Popup.Target as={FunctionComponent} /> If allowed, the HTML attribute interface is unknowable unless the ForwardComponent<Popup.Target as={ForwardComponent} /> We can guess that the HTML attribute interface will probably be the same as the ElementComponent<Popup.Target as={ElementComponent} /> Although not a stronger guarantee of proper use, |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Compound components allow an
as
prop to be passed. Theas
could be a element like'div'
or'button'
, but could also be another component. There are a few types of components that are allowed:ElementComponent<any, Props>
React.FC<Props>
React.ForwardRefExoticComponent<Props & React.RefAttributes<any>>
A component passed in should forward a ref and spread props. Typescript has no way to enforce prop spreading or even proper prop merging. An example on prop merging using our
mergeProps
utility function will callonClick
callback instead of overriding it.An example of an
ElementComponent
being passed another component:What happens is the
Popup.Target
will render aDeleteButton
, forwarding aref
and all props provided byusePopupTarget
to theDeleteButton
. It is up toDeleteButton
to properly apply and merge props with its own props to the underlying element which should also forward theref
to the same underlying element.Question 1:
Should a
React.FC
component be allowed in theas
?Not all our
ElementComponent
's need theref
to be forwarded, but none explicitly state they do. The safe option is to assume ref forwarding is always needed.Question 2:
Should the
Props
of the providedas
component be implicitly merged in types.Examples:
Beta Was this translation helpful? Give feedback.
All reactions