Created
July 26, 2019 18:51
-
-
Save mrcoles/ebd34c3a3ca39614c8ad250e5f83e9be to your computer and use it in GitHub Desktop.
A simple React component for handling pluralization of a word.
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
import React from 'react'; | |
export const Plural = ({ | |
num, | |
text, | |
pluralText, | |
pluralSuffix, | |
singularSuffix | |
}: { | |
num: number; | |
text: string; | |
pluralText?: string; | |
pluralSuffix?: string; | |
singularSuffix?: string; | |
}) => { | |
return ( | |
<> | |
{num === 1 | |
? text + (singularSuffix || '') | |
: pluralText | |
? pluralText | |
: text + (pluralSuffix || 's')} | |
</> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
π¦ π ππ