11import cx from 'clsx'
22import _ from 'lodash'
33import PropTypes from 'prop-types'
4- import React , { Component } from 'react'
4+ import React from 'react'
55
66import {
77 childrenUtils ,
@@ -10,35 +10,31 @@ import {
1010 getUnhandledProps ,
1111 getElementType ,
1212 useKeyOnly ,
13+ useEventCallback ,
1314} from '../../lib'
1415
1516/**
1617 * A section sub-component for Breadcrumb component.
1718 */
18- export default class BreadcrumbSection extends Component {
19- computeElementType = ( ) => {
20- const { link, onClick } = this . props
19+ const BreadcrumbSection = React . forwardRef ( function ( props , ref ) {
20+ const { active, children, className, content, href, link, onClick } = props
2121
22+ const classes = cx ( useKeyOnly ( active , 'active' ) , 'section' , className )
23+ const rest = getUnhandledProps ( BreadcrumbSection , props )
24+ const ElementType = getElementType ( BreadcrumbSection , props , ( ) => {
2225 if ( link || onClick ) return 'a'
23- }
26+ } )
2427
25- handleClick = ( e ) => _ . invoke ( this . props , 'onClick' , e , this . props )
28+ const handleClick = useEventCallback ( ( e ) => _ . invoke ( props , 'onClick' , e , props ) )
2629
27- render ( ) {
28- const { active, children, className, content, href } = this . props
29-
30- const classes = cx ( useKeyOnly ( active , 'active' ) , 'section' , className )
31- const rest = getUnhandledProps ( BreadcrumbSection , this . props )
32- const ElementType = getElementType ( BreadcrumbSection , this . props , this . computeElementType )
33-
34- return (
35- < ElementType { ...rest } className = { classes } href = { href } onClick = { this . handleClick } >
36- { childrenUtils . isNil ( children ) ? content : children }
37- </ ElementType >
38- )
39- }
40- }
30+ return (
31+ < ElementType { ...rest } className = { classes } href = { href } onClick = { handleClick } ref = { ref } >
32+ { childrenUtils . isNil ( children ) ? content : children }
33+ </ ElementType >
34+ )
35+ } )
4136
37+ BreadcrumbSection . displayName = 'BreadcrumbSection'
4238BreadcrumbSection . propTypes = {
4339 /** An element type to render as (string or function). */
4440 as : PropTypes . elementType ,
@@ -75,3 +71,5 @@ BreadcrumbSection.create = createShorthandFactory(BreadcrumbSection, (content) =
7571 content,
7672 link : true ,
7773} ) )
74+
75+ export default BreadcrumbSection
0 commit comments