Skip to content

Commit

Permalink
chore(bar): refactor commonProps for reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
wyze committed Jun 28, 2021
1 parent 3f0bb4e commit 82262a2
Showing 1 changed file with 32 additions and 41 deletions.
73 changes: 32 additions & 41 deletions packages/bar/src/Bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,20 +186,36 @@ const InnerBar = <RawDatum extends BarDatum>({
[enableLabel, labelSkipHeight, labelSkipWidth]
)

const commonProps = {
borderRadius,
borderWidth,
enableLabel,
isInteractive,
labelSkipWidth,
labelSkipHeight,
onClick,
onMouseEnter,
onMouseLeave,
getTooltipLabel,
tooltipFormat,
tooltip,
}
const commonProps = useMemo(
() => ({
borderRadius,
borderWidth,
enableLabel,
isInteractive,
labelSkipWidth,
labelSkipHeight,
onClick,
onMouseEnter,
onMouseLeave,
getTooltipLabel,
tooltipFormat,
tooltip,
}),
[
borderRadius,
borderWidth,
enableLabel,
getTooltipLabel,
isInteractive,
labelSkipHeight,
labelSkipWidth,
onClick,
onMouseEnter,
onMouseLeave,
tooltip,
tooltipFormat,
]
)

const boundDefs = bindDefs(defs, result.bars, fill, {
dataKey: 'data',
Expand Down Expand Up @@ -313,35 +329,10 @@ const InnerBar = <RawDatum extends BarDatum>({
// We use `any` here until we can figure out the best way to type xScale/yScale
const layerContext: any = useMemo(
() => ({
borderRadius,
borderWidth,
enableLabel,
isInteractive,
labelSkipWidth,
labelSkipHeight,
onClick,
onMouseEnter,
onMouseLeave,
getTooltipLabel,
tooltipFormat,
tooltip,
...commonProps,
...result,
}),
[
borderRadius,
borderWidth,
enableLabel,
getTooltipLabel,
isInteractive,
labelSkipHeight,
labelSkipWidth,
onClick,
onMouseEnter,
onMouseLeave,
result,
tooltip,
tooltipFormat,
]
[commonProps, result]
)

return (
Expand Down

0 comments on commit 82262a2

Please sign in to comment.