-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(getElementType): add lib function
- Loading branch information
1 parent
682c124
commit 08a3a7b
Showing
2 changed files
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters