You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* A hook to fetch data from the Jetpack API using react-query
7
+
* Custom hook for fetching data from the Jetpack API, utilizing the react-query library for data fetching and caching.
8
+
* This hook abstracts the common setup needed for calling the Jetpack API, such as setting the API root and nonce,
9
+
* and provides react-query's powerful features like caching and automatic refetching.
7
10
*
8
-
* @param {string} name - The name of the query.
9
-
* @param {Function} queryFn - The function that fetches the data.
10
-
* @param {string} explicitKey - An optional key to use for the query cache.
11
-
* @param {string} errorMessage - An optional custom error message to display.
12
-
* @returns {Array} The result of the query.
11
+
* @template T The type of data expected to be returned by the query function.
12
+
* @param {object} params - The parameters for configuring the API query.
13
+
* @param {string} params.name - The unique name for the query. This name, along with the optional `explicitKey`, forms the cache key for the query's result.
14
+
* @param {Function} params.queryFn - The function to fetch data from the API. It receives a configured instance of `restApi` and must return a promise that resolves to the data of type `T`.
15
+
* @param {string} [params.errorMessage] - Optional. A custom error message to be displayed in case the query fails. This message overrides the default error handling behavior.
16
+
* @returns {UseQueryResult<T>} The result object from the useQuery hook, containing data and state information about the query (e.g., isLoading, isError).
* Simple wrapper for useQuery that handles error notices.
7
+
/**
8
+
* Executes a mutation with the specified parameters and options. This hook is designed
9
+
* for performing data modification operations (e.g., POST, PUT, DELETE requests) and handling
10
+
* the mutation's lifecycle events, such as success or failure. Additionally, it can display
11
+
* an error notice if the mutation encounters an error.
9
12
*
10
-
* This query is meant for any methods that include updating data (e.g. POST or DELETE), if you need to use a GET request, use useSimpleQuery.
11
-
*
12
-
* The options object is optional and is a strictly defined subset of the UseMutationOptions type.
13
-
* If you want to pass more options, you can add them to the options type above.
13
+
* @template T The type of data expected to be returned by the mutation.
14
+
* @param {object} params - The parameters for executing the mutation.
15
+
* @param {string} params.name - A unique name for the mutation, used as part of the mutation key.
16
+
* @param {APIFetchOptions} params.query - The options to be passed to the API fetch function for the mutation.
17
+
* @param {Pick<UseMutationOptions, 'onSuccess'>} [params.options] - Optional. Mutation options from react-query, currently supports only the 'onSuccess' option.
18
+
* @param {string} [params.errorMessage] - Optional. A custom error message that can be displayed if the mutation fails.
19
+
* @returns {UseMutationResult<T>} The result object from the useMutation hook, containing data and state information about the mutation (e.g., isPending, isError).
0 commit comments