Skip to content

Commit

Permalink
StyledOcticon/Octicon: Update the render func to use `React.forwardRe…
Browse files Browse the repository at this point in the history
…f()` (#3293)

* forwardref styl octiocns

* remove the comment

* add changeset
  • Loading branch information
broccolinisoup authored May 17, 2023
1 parent 434f542 commit 027d214
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/spicy-shoes-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Octicons (previously known StyledOcticons) to use React.forwardRef()
7 changes: 4 additions & 3 deletions src/Octicon/Octicon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import {ComponentProps} from '../utils/types'

type StyledOcticonProps = {icon: React.ElementType; color?: string} & IconProps

function Icon({icon: IconComponent, ...rest}: StyledOcticonProps) {
return <IconComponent {...rest} />
}
const Icon = React.forwardRef((props: StyledOcticonProps, ref: React.Ref<SVGSVGElement>) => {
const {icon: IconComponent, ...rest} = props
return <IconComponent {...rest} ref={ref} />
})

const Octicon = styled(Icon)<SxProp>`
${({color, sx: sxProp}) => sx({sx: {color, ...sxProp}})}
Expand Down

0 comments on commit 027d214

Please sign in to comment.