ixfx
    Preparing search index...

    Function getWithFallback

    • Computes the styles for elt (or defaults to document.body) using fallback as a set of default values.

      // Fetch styles
      const styles = getWithFallback({
      my_var: `red`
      }, element);

      // Access --my-var, or if it doesn't exist returns 'red'
      styles.my_var;

      Hyphen case (eg 'my-var') is a common way of delimiting words in CSS variables, but can't be (elegantly) used in object properties. Instead, use '_' in the object key, which is replaced with '-'.

      The leading '--' is not needed either.

      Type Parameters

      • TextendsRecord<string, string | number>

      Parameters

      • fallback: T
      • Optionalelt: Element

      Returns T