Home > @shopware-pwa/composables > useDefaults

# useDefaults() function

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Returns default config depending on config key. It is used in composables, so defaultsKey is in most cases composable name (ex. useDefaults({ defaultsKey: "useCms" }))

Signature:

export declare function useDefaults(params: {
    defaultsKey: string;
}): {
    getIncludesConfig: () => Includes;
    getAssociationsConfig: () => ShopwareAssociation;
    getDefaults: () => ShopwareSearchParams;
};

# Parameters

Parameter Type Description
params { defaultsKey: string; }

Returns:

{ getIncludesConfig: () => Includes; getAssociationsConfig: () => ShopwareAssociation; getDefaults: () => ShopwareSearchParams; }

# Remarks

To extend defaults you need to add configuration to shopware-pwa.config.js file. Let's say we want to add product new_option field and change listing limit on CMS pages. We need to add to configuration file:

// inside shopware-pwa.config.js
const defaultsConfigBuilder =
  require("@shopware-pwa/nuxt-module/api-defaults").default
`
defaultsConfigBuilder()
  .replace("useCms.limit", 8) // change default listing limit to 8
  .add("useCms.includes.product", "new_option") // add product new_option to returned fields

module.exports = {
  // ... your standard Shopware PWA settings
}

We need to remember the structure of includes and associations. You can read more about this in shopware docs (opens new window).