Skip to content

Commit

Permalink
fix: GetComponentName was crashing when using string arg
Browse files Browse the repository at this point in the history
  • Loading branch information
JF-Cozy committed Jun 1, 2023
1 parent d7a0f04 commit df8647f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions react/utils/react.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { Fragment, Children } from 'react'

export const getComponentName = component => {
if (!component) return null
return component.type.displayName || component.type.name || 'Component'
/**
* Get the name of the node
* @param {React.ElementType || string} node
* @returns
*/
export const getComponentName = node => {
if (!node) return null
// type is defined only if we use a node, but a string could be passed to
// and so, there is no type
return node.type?.displayName || node.type?.name || 'Node'
}

export const getChildren = props => {
Expand Down

0 comments on commit df8647f

Please sign in to comment.