Skip to content

Commit

Permalink
fix(Button): memoize call to merge.all (#2252)
Browse files Browse the repository at this point in the history
* fix(Button): memoize call to merge.all

* refactor(button): remove sxProp from useMemo call

* chore: add changeset
  • Loading branch information
joshblack committed Sep 6, 2022
1 parent 8ea1f75 commit e52415e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/shy-flowers-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Update ButtonBase.tsx to memoize calls to styles to improve performance
13 changes: 5 additions & 8 deletions src/Button/ButtonBase.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {ComponentPropsWithRef, forwardRef} from 'react'
import React, {ComponentPropsWithRef, forwardRef, useMemo} from 'react'
import {ForwardRefComponent as PolymorphicForwardRefComponent} from '../utils/polymorphic'
import Box from '../Box'
import {merge, SxProp} from '../sx'
Expand All @@ -13,14 +13,11 @@ const ButtonBase = forwardRef<HTMLElement, ButtonProps>(
const iconWrapStyles = {
display: 'inline-block'
}
const sxStyles = merge.all([
getButtonStyles(theme),
getSizeStyles(size, variant, false),
getVariantStyles(variant, theme),
sxProp as SxProp
])
const sxStyles = useMemo(() => {
return merge.all([getButtonStyles(theme), getSizeStyles(size, variant, false), getVariantStyles(variant, theme)])
}, [theme, size, variant])
return (
<StyledButton as={Component} sx={sxStyles} {...props} ref={forwardedRef}>
<StyledButton as={Component} sx={merge(sxStyles, sxProp as SxProp)} {...props} ref={forwardedRef}>
{LeadingIcon && (
<Box as="span" data-component="leadingIcon" sx={iconWrapStyles}>
<LeadingIcon />
Expand Down

0 comments on commit e52415e

Please sign in to comment.