Skip to content

Commit

Permalink
feat(pie): use optional chaining and nullish coalescing
Browse files Browse the repository at this point in the history
  • Loading branch information
plouc committed Nov 5, 2020
1 parent ff242a9 commit a770ed5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/pie/src/PieCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const PieCanvas = <R, >({

legends = defaultProps.legends,
}: PieCanvasProps<R>) => {
const canvasEl = useRef<HTMLCanvasElement>(null)
const canvasEl = useRef<HTMLCanvasElement | null>(null)
const theme = useTheme()

const { margin, innerWidth, innerHeight, outerWidth, outerHeight } = useDimensions(
Expand Down Expand Up @@ -296,7 +296,7 @@ const PieCanvas = <R, >({
const handleMouseHover = (event: React.MouseEvent<HTMLCanvasElement>) => {
const datum = getArcFromMouse(event)
if (datum) {
if (onMouseMove) onMouseMove(datum, event)
onMouseMove?.(datum, event)
showTooltipFromEvent(createElement(tooltip, { datum }), event)
} else {
hideTooltip()
Expand Down
8 changes: 4 additions & 4 deletions packages/pie/src/PieSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,31 @@ export const PieSlice = <R, >({

const handleMouseEnter = useCallback(
event => {
if (onMouseEnter) onMouseEnter(datum, event)
onMouseEnter?.(datum, event)
handleTooltip(event)
},
[onMouseEnter, handleTooltip, datum]
)

const handleMouseMove = useCallback(
event => {
if (onMouseMove) onMouseMove(datum, event)
onMouseMove?.(datum, event)
handleTooltip(event)
},
[onMouseMove, handleTooltip, datum]
)

const handleMouseLeave = useCallback(
event => {
if (onMouseLeave) onMouseLeave(datum, event)
onMouseLeave?.(datum, event)
hideTooltip(event)
},
[onMouseLeave, hideTooltip, datum]
)

const handleClick = useCallback(
event => {
if (onClick) onClick(datum, event)
onClick?.(datum, event)
},
[onClick, datum]
)
Expand Down
2 changes: 1 addition & 1 deletion packages/pie/src/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ export const defaultProps = {

role: 'img',

pixelRatio: window && window.devicePixelRatio ? window.devicePixelRatio : 1,
pixelRatio: window?.devicePixelRatio ?? 1,
}

0 comments on commit a770ed5

Please sign in to comment.