Created
October 9, 2021 08:24
-
-
Save dsdeur/6a096eb12e1bea128c69e4bcf36fd763 to your computer and use it in GitHub Desktop.
Util function to combine classNames conditionally
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
function join( | |
...classNames: ([boolean, string] | string | undefined | null)[] | |
) { | |
let result = ""; | |
for (let x = 0; x < classNames.length; x++) { | |
const value = classNames[x]; | |
if (!value) continue; | |
if (typeof value === "string") { | |
result += " " + value; | |
continue; | |
} | |
if (value[0]) result += " " + value[1]; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment