-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[docs] Add Tooltip TypeScript demos #15061
Conversation
No bundle size changes comparing 6981a04...375336f |
|
||
function CustomizedTooltips() { | ||
const classes = useStyles(); | ||
const [arrowRef, setArrowRef] = React.useState<HTMLSpanElement | null>(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Dudrie Try implementing the same feature with
const [arrowRef, setArrowRef] = React.useState<HTMLSpanElement | null>(null); | |
const arrowRef = React.useRef<HTMLSpanElement>(null); |
You will probably need quite a bit of additional code to handle re-rendering.
The current implementation is a smart way to avoid creating ref callbacks and forceUpdate
methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right, useRef
does not trigger a re-render if it's current
changes. Using this hook would probably add more boilerplate code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly it's one of the reasons I don't like the ref
suffix. When used right it doesn't add information but if used wrong it adds confusion. Simply using arrowNode
would've been clearer and then it would also be obvious that setArrowNode
should only be used in ref
props for host or ref forwarding components.
But there's no reason to change this now. Discussions regarding this haven't been very helpful to either side anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to comment on the ref
suffix situation last time. For me I don’t think the ref suffix is needed most of the time. I guess I would use it when passing something to the ref
prop.
@Dudrie Thank you! |
Here are the TypeScript demos for the tooltip components. A few of them did not need additional typing, so I did just create the corresponding
tsx
file for them.However, I had a question while doing so: In CustomizedTooltip
useState
is used to create a ref. Is there a reason why theuseRef
hook is not used there?