Skip to content

Commit

Permalink
Revert "Remove custom options for react query hoc (#755)"
Browse files Browse the repository at this point in the history
This reverts commit 9e0f596.
  • Loading branch information
kevinxh authored Oct 18, 2022
1 parent 4e197d1 commit 21e804d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 9 deletions.
21 changes: 18 additions & 3 deletions packages/commerce-sdk-react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ A library of React hooks for fetching data from Salesforce B2C Commerce.

The full documentation for PWA Kit and Managed Runtime is hosted on the [Salesforce Developers](https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/overview) portal.


## PWA-Kit Integration

> To integration this library with your PWA-Kit application you can use the `CommerceApiProvider` directly given that you use the `withReactQuery` higher order component to wrap your `AppConfig` component. Below is a snippet of how this is accomplished.
Expand All @@ -21,9 +22,24 @@ const AppConfig = ({children}) => {
{children}
</CommerceApiProvider>
)
}
// Set configuration options for react query.
// NOTE: This configuration will be used both on the server-side and client-side.
const options = {
queryClientConfig: {
defaultOptions: {
queries: {
retry: false
},
mutations: {
retry: false
}
}
}
}
export default withReactQuery(AppConfig)
export default withReactQuery(AppConfig, options)
```

## Generic Integration
Expand All @@ -44,11 +60,10 @@ const App = ({children}) => {
</CommerceApiProvider>
</QueryClientProvider>
)
}
}
export default App
```

### Useful Links:

- [Get Started](https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/getting-started.html)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ const SAFE_QUERY_CLIENT_CONFIG = {
* A HoC for adding React Query support to your application.
*
* @param {React.ReactElement} Wrapped The component to be wrapped
* @param {Object} options
* @param {Object} options.queryClientConfig The react query client configuration object to be used. By
* default the `retry` option will be set to false to ensure performant server rendering.
*
* @returns {React.ReactElement}
*/
export const withReactQuery = (Wrapped) => {
export const withReactQuery = (Wrapped, options = {}) => {
const isServerSide = typeof window === 'undefined'
/* istanbul ignore next */
const wrappedComponentName = Wrapped.displayName || Wrapped.name

// @TODO: allow user to configure react query
const queryClientConfig = SAFE_QUERY_CLIENT_CONFIG
const queryClientConfig = options.queryClientConfig || SAFE_QUERY_CLIENT_CONFIG

/**
* @private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,18 @@ import {withLegacyGetProps} from 'pwa-kit-react-sdk/ssr/universal/components/wit
import {withReactQuery} from 'pwa-kit-react-sdk/ssr/universal/components/with-react-query'
import AppConfig from 'pwa-kit-react-sdk/ssr/universal/components/_app-config'

export default withReactQuery(withLegacyGetProps(AppConfig))
// Recommended settings for PWA-Kit usages.
const options = {
queryClientConfig: {
defaultOptions: {
queries: {
retry: false
},
mutations: {
retry: false
}
}
}
}

export default withReactQuery(withLegacyGetProps(AppConfig), options)
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,18 @@ AppConfig.restore = () => {}
AppConfig.extraGetPropsArgs = () => {}
AppConfig.freeze = () => {}

export default withReactQuery(AppConfig)
// Recommended settings for PWA-Kit usage.
const options = {
queryClientConfig: {
defaultOptions: {
queries: {
retry: false
},
mutations: {
retry: false
}
}
}
}

export default withReactQuery(AppConfig, options)

0 comments on commit 21e804d

Please sign in to comment.