(props: StringProps)
| 54 | } |
| 55 | |
| 56 | export function String(props: StringProps): React.ReactElement | null { |
| 57 | const { stringID, vars, useRichText, tagName, ...rest } = props |
| 58 | const { getString } = useStrings() |
| 59 | const Tag = tagName as ElementType |
| 60 | |
| 61 | try { |
| 62 | const text = getString(stringID, vars) |
| 63 | |
| 64 | return useRichText ? ( |
| 65 | <Tag {...(rest as unknown as {})} dangerouslySetInnerHTML={{ __html: text }} /> |
| 66 | ) : ( |
| 67 | <Tag {...(rest as unknown as {})}>{text}</Tag> |
| 68 | ) |
| 69 | } catch (e) { |
| 70 | if (process.env.NODE_ENV !== 'production') { |
| 71 | return <Tag style={{ color: 'var(--red-500)' }}>{get(e, 'message', e)}</Tag> |
| 72 | } |
| 73 | |
| 74 | return null |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | String.defaultProps = { |
| 79 | tagName: 'span' |
no test coverage detected
searching dependent graphs…