Skip to content

Commit

Permalink
fix: text 为字符串时直接显示
Browse files Browse the repository at this point in the history
  • Loading branch information
cncolder committed Jun 10, 2020
1 parent 9e82004 commit 4a9abe4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ export interface BadgeProps {
maxValue?: number
}

export const Badge: React.FC<BadgeProps> = props => {
export const Badge: React.FC<BadgeProps> = (props) => {
const { className, style, children, dot, value, maxValue = 99 } = props

const text = useMemo(() => {
const num = Number(value)

return Number.isInteger(num) ? (num > maxValue ? `${maxValue}+` : value?.toString()) : ''
if (Number.isInteger(num)) {
return num > maxValue ? `${maxValue}+` : num.toString()
} else if (typeof value === 'string') {
return value
} else {
return ''
}
}, [value, maxValue])

return (
Expand Down

0 comments on commit 4a9abe4

Please sign in to comment.