Function useCache

  • Think of this as useMemo but across component instances

    Example

     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;
    };

    Type Parameters

    • Value

    Parameters

    • create: (() => Value)

      Function that creates the item to be cached

        • (): Value
        • Returns Value

    • deps: unknown[]

      list of dependencies. Make sure there is a unique value to avoid collisions

    Returns Value

    value returned by create function

Generated using TypeDoc