From a770ed518f8939f97e9c183db7142013a0f95f6e Mon Sep 17 00:00:00 2001 From: plouc Date: Fri, 6 Nov 2020 07:46:23 +0900 Subject: [PATCH] feat(pie): use optional chaining and nullish coalescing --- packages/pie/src/PieCanvas.tsx | 4 ++-- packages/pie/src/PieSlice.tsx | 8 ++++---- packages/pie/src/props.ts | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/pie/src/PieCanvas.tsx b/packages/pie/src/PieCanvas.tsx index 26411f3a4..146aa6f86 100644 --- a/packages/pie/src/PieCanvas.tsx +++ b/packages/pie/src/PieCanvas.tsx @@ -128,7 +128,7 @@ const PieCanvas = ({ legends = defaultProps.legends, }: PieCanvasProps) => { - const canvasEl = useRef(null) + const canvasEl = useRef(null) const theme = useTheme() const { margin, innerWidth, innerHeight, outerWidth, outerHeight } = useDimensions( @@ -296,7 +296,7 @@ const PieCanvas = ({ const handleMouseHover = (event: React.MouseEvent) => { const datum = getArcFromMouse(event) if (datum) { - if (onMouseMove) onMouseMove(datum, event) + onMouseMove?.(datum, event) showTooltipFromEvent(createElement(tooltip, { datum }), event) } else { hideTooltip() diff --git a/packages/pie/src/PieSlice.tsx b/packages/pie/src/PieSlice.tsx index b739a2160..a0143046f 100644 --- a/packages/pie/src/PieSlice.tsx +++ b/packages/pie/src/PieSlice.tsx @@ -38,7 +38,7 @@ export const PieSlice = ({ const handleMouseEnter = useCallback( event => { - if (onMouseEnter) onMouseEnter(datum, event) + onMouseEnter?.(datum, event) handleTooltip(event) }, [onMouseEnter, handleTooltip, datum] @@ -46,7 +46,7 @@ export const PieSlice = ({ const handleMouseMove = useCallback( event => { - if (onMouseMove) onMouseMove(datum, event) + onMouseMove?.(datum, event) handleTooltip(event) }, [onMouseMove, handleTooltip, datum] @@ -54,7 +54,7 @@ export const PieSlice = ({ const handleMouseLeave = useCallback( event => { - if (onMouseLeave) onMouseLeave(datum, event) + onMouseLeave?.(datum, event) hideTooltip(event) }, [onMouseLeave, hideTooltip, datum] @@ -62,7 +62,7 @@ export const PieSlice = ({ const handleClick = useCallback( event => { - if (onClick) onClick(datum, event) + onClick?.(datum, event) }, [onClick, datum] ) diff --git a/packages/pie/src/props.ts b/packages/pie/src/props.ts index 78ea9884d..b451c0343 100644 --- a/packages/pie/src/props.ts +++ b/packages/pie/src/props.ts @@ -58,5 +58,5 @@ export const defaultProps = { role: 'img', - pixelRatio: window && window.devicePixelRatio ? window.devicePixelRatio : 1, + pixelRatio: window?.devicePixelRatio ?? 1, }