Created
May 30, 2020 09:05
-
-
Save atmin/b4fbcd4bec18feea27adf0cd6a3b3d5d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function dom<T extends HTMLElement>( | |
name: string, | |
props: { [key in keyof T]?: any } = {}, | |
children: Array<HTMLElement> = [] | |
): T { | |
const result = document.createElement(name); | |
Object.entries(props).forEach(([name, prop]) => (result[name] = prop)); | |
children.forEach(child => result.append(child)); | |
return result as T; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment