react-icons/fa APIs
- FaTwitter
- FaGithub
- FaSearch
- FaDiscord
- FaEye
- FaInstagram
- FaPlus
- FaFacebookF
- FaTrash
- FaGlobe
- FaUsers
- FaEdit
- FaListUl
- FaWhatsapp
- FaApple
- FaTimes
- FaMoon
- FaSun
- FaYoutube
- FaInfoCircle
- FaSave
- FaEyeSlash
- FaCheck
- FaRegCheckCircle
- FaExternalLinkAlt
- FaChevronUp
- FaChevronDown
- FaUser
- FaThumbsUp
- FaGoogle
- FaChevronLeft
- FaTrashAlt
- FaCheckCircle
- FaExclamationCircle
- FaCode
- FaFilter
- FaLinkedinIn
- FaHome
- FaAngleRight
- FaAngleLeft
- FaCopy
- FaArrowRight
- FaThumbsDown
- FaTimesCircle
- FaMapMarkedAlt
- FaNetworkWired
- FaFacebook
- FaMedal
- FaQuestionCircle
- FaAppStoreIos
- FaRegNewspaper
- FaLinkedin
- FaAward
- FaSpinner
- FaBell
- FaLink
- FaCog
- FaCaretDown
- FaCaretLeft
- FaCaretRight
- FaRegQuestionCircle
- FaSignInAlt
- FaRegCircle
- FaPlayCircle
- FaBook
- FaMinus
- FaRegClock
- FaRegTimesCircle
- FaUserClock
- FaClipboardCheck
- FaTelegram
- FaToolbox
- FaCalendarAlt
- FaChevronCircleDown
- FaChevronCircleUp
- FaChevronCircleRight
- FaCogs
- FaDownload
- FaSitemap
- FaTrophy
- FaGripVertical
- FaFlagCheckered
- FaMapMarkerAlt
- FaChrome
- FaRegStickyNote
- FaRegSun
- FaTags
- FaGetPocket
- FaRegEdit
- FaRobot
- FaDev
- FaQuora
- FaGraduationCap
- FaClipboard
- FaVine
- FaMicroscope
- FaReact
- FaVuejs
- FaPalette
- FaPen
- FaSmile
- FaPaperPlane
- FaImage
- FaUserPlus
- FaAnchor
- FaCaretUp
- FaRss
- FaRegLightbulb
- FaStar
- FaSignOutAlt
- FaUserMinus
- FaEnvelopeOpenText
- FaPencilAlt
- FaExclamation
- FaUnlock
- FaLock
- FaSlack
- FaUserCircle
- FaEnvelope
- FaKey
- FaRegStar
- FaWrench
- FaMarkdown
- FaArrowCircleLeft
- FaArrowCircleRight
- FaScroll
- FaUserFriends
- FaBolt
- FaExpand
- FaLocationArrow
- FaStopCircle
- FaHandHolding
- FaPhotoVideo
- FaShareAlt
- FaVoicemail
- FaGithubAlt
- FaLifeRing
- FaSyncAlt
- FaSoundcloud
- FaSpotify
- FaHistory
- FaBloggerB
- FaDrawPolygon
- FaHandPaper
- FaHandPointer
- FaPhone
- FaList
- FaMailBulk
- FaHourglass
- FaMediumM
- FaPlay
- FaGift
- FaChevronRight
- FaLongArrowAltRight
- FaMedium
- FaWindowClose
- FaEllipsisH
- FaVolumeUp
- FaVolumeMute
- FaKeyboard
- FaHammer
- FaFileImport
- FaListOl
- FaSquare
- FaFillDrip
- FaUserLock
- FaRegPlusSquare
- FaRegFile
- FaSlash
- FaCloudUploadAlt
- FaBackspace
- FaAngleDoubleRight
- FaAngleDoubleLeft
- FaGlasses
- FaPause
- FaCheckSquare
- FaComment
- FaPrint
- FaShareSquare
- FaChartBar
- FaMagic
- FaBicycle
- FaCat
- FaDirections
- FaGlobeAfrica
- FaMountain
- FaUpload
- FaLightbulb
- FaDocker
- FaTwitterSquare
- FaGlobeAmericas
- FaLinux
- FaFile
- FaDesktop
- FaFacebookMessenger
- FaWpforms
- FaBomb
- FaBars
- FaTabletAlt
- FaMemory
- FaCalendarDay
- Fa500Px
- FaAdobe
- FaAdversal
- FaAirbnb
- FaAlipay
- FaAmazon
- FaAmazonPay
- FaBehanceSquare
- FaInstagramSquare
- FaLaugh
- FaMagento
- FaOpera
- FaYinYang
Other Related APIs
react-icons/fa#FaRegStar TypeScript Examples
The following examples show how to use
react-icons/fa#FaRegStar.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StarButton.tsx From hub with Apache License 2.0 | 4 votes |
StarButton = (props: Props) => {
const { ctx, dispatch } = useContext(AppCtx);
const history = useHistory();
const [packageStars, setPackageStars] = useState<PackageStars | undefined | null>(undefined);
const [isSending, setIsSending] = useState(false);
const [isGettingIfStarred, setIsGettingIfStarred] = useState<boolean | undefined>(undefined);
const [pkgId, setPkgId] = useState<string>(props.packageId);
const point = useBreakpointDetect();
const notLoginUser = isUndefined(ctx.user) || isNull(ctx.user);
const [enabledTooltip, setEnabledTooltip] = useState<boolean>(false);
async function getPackageStars() {
try {
setIsGettingIfStarred(true);
setPackageStars(await API.getStars(props.packageId));
setIsGettingIfStarred(false);
} catch {
setPackageStars(null);
setIsGettingIfStarred(false);
}
}
useEffect(() => {
if (
(!isUndefined(ctx.user) &&
(isUndefined(packageStars) ||
(!isNull(ctx.user) && isUndefined(packageStars!.starredByUser)) ||
(isNull(ctx.user) && packageStars!.starredByUser))) ||
props.packageId !== pkgId
) {
setPkgId(props.packageId);
getPackageStars();
}
}, [ctx.user, props.packageId]); /* eslint-disable-line react-hooks/exhaustive-deps */
const notStarred =
!isUndefined(ctx.user) &&
(isNull(ctx.user) ||
(!isNull(ctx.user) &&
!isUndefined(packageStars) &&
!isNull(packageStars) &&
!isUndefined(packageStars.starredByUser) &&
!packageStars.starredByUser));
async function handleToggleStar() {
try {
setIsSending(true);
await API.toggleStar(props.packageId);
getPackageStars();
setIsSending(false);
} catch (err: any) {
setIsSending(false);
// On unauthorized, we force sign out
if (err.kind === ErrorKind.Unauthorized) {
dispatch(signOut());
history.push(`${window.location.pathname}?modal=login&redirect=${window.location.pathname}`);
} else {
let errMessage = `An error occurred ${
notStarred ? 'starring' : 'unstarring'
} the package, please try again later.`;
alertDispatcher.postAlert({
type: 'danger',
message: errMessage,
});
}
}
}
useEffect(() => {
let timeout: NodeJS.Timeout;
if (enabledTooltip) {
// Hide tooltip after 2s
timeout = setTimeout(() => setEnabledTooltip(false), 2 * 1000);
}
return () => {
if (!isUndefined(timeout)) {
clearTimeout(timeout);
}
};
}, [enabledTooltip]);
if (isUndefined(ctx.user) || isUndefined(packageStars) || isNull(packageStars)) return null;
return (
<>
<div className={`ms-auto d-flex flex-row align-items-center position-relative ${styles.wrapper}`}>
<ElementWithTooltip
active
className={styles.starBtnWrapper}
element={
<button
className={classnames('btn btn-sm btn-primary px-1 px-md-3 position-relative starBtn', styles.starBtn, {
[`disabled ${styles.disabled}`]: notLoginUser || isGettingIfStarred,
})}
type="button"
onClick={() => {
if (!isGettingIfStarred) {
if (notLoginUser) {
if ([point && 'xs', 'sm'].includes(point)) {
setEnabledTooltip(true);
}
} else {
handleToggleStar();
}
}
}}
aria-label={`${notStarred ? 'Star' : 'Unstar'} package`}
>
<div className="d-flex align-items-center">
{notStarred ? <FaRegStar className={styles.icon} /> : <FaStar className={styles.icon} />}
<span className="ms-2">{notStarred ? 'Star' : 'Unstar'}</span>
</div>
</button>
}
tooltipMessage="You must be signed in to star a package"
visibleTooltip={isNull(ctx.user)}
/>
<span className={`badge bg-light text-dark text-center px-3 border border-start-0 lh-base ${styles.starBadge}`}>
{isNumber(packageStars.stars) ? prettifyNumber(packageStars.stars) : '-'}
</span>
{(isSending || isGettingIfStarred) && (
<div className={`position-absolute ${styles.spinner}`} role="status">
<span className="spinner-border spinner-border-sm text-primary" />
</div>
)}
</div>
</>
);
}