Skip to content

Commit

Permalink
feat(getElementType): add lib function
Browse files Browse the repository at this point in the history
  • Loading branch information
levithomason committed Aug 21, 2016
1 parent 682c124 commit 08a3a7b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/lib/getElementType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Returns a createElement() type based on the props of the Component.
* Useful for calculating what type a component should render as.
*
* @param {object} props A ReactElement props object
* @returns {string|function} A ReactElement type
*/
function getElementType(props) {
const { el } = props

// use defined el
if (el) return el

// infer anchor links
if (props.href) return 'a'

return props.defaultEl || 'div'
}

export default getElementType
1 change: 1 addition & 0 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export {
} from './deprecate'

export { default as getUnhandledProps } from './getUnhandledProps'
export { default as getElementType } from './getElementType'
export * as META from './META'
export * as SUI from './SUI'

Expand Down

0 comments on commit 08a3a7b

Please sign in to comment.