Think of this as useMemo but across component instances
export const FormattedRelativeTime = ({ value, unit, ...options }: FormattedRelativeTimeProps) => { const { i18n } = useLingui(); const formatter = useCache( () => new Intl.RelativeTimeFormat(i18n.locale, options), ["FormattedRelativeTime", i18n.locale, JSON.stringify(options)] ); return formatter.format(value, unit) as unknown as JSX.Element; }; Copy
export const FormattedRelativeTime = ({ value, unit, ...options }: FormattedRelativeTimeProps) => { const { i18n } = useLingui(); const formatter = useCache( () => new Intl.RelativeTimeFormat(i18n.locale, options), ["FormattedRelativeTime", i18n.locale, JSON.stringify(options)] ); return formatter.format(value, unit) as unknown as JSX.Element; };
Function that creates the item to be cached
list of dependencies. Make sure there is a unique value to avoid collisions
value returned by create function
Generated using TypeDoc
Think of this as useMemo but across component instances
Example