Extra axios options are not generated for react-query
See original GitHub issueHi, I need to pass additional options to axios, but can’t find a way to do this with react-query client (haven’t tested with other clients).
I have this config:
import { defineConfig } from 'orval';
export default defineConfig({
server: {
input: 'http://server:8000/api/v1/schema.json',
output: {
target: './src/restTypes.ts',
client: 'react-query',
override: {
mutator: {
path: './src/hooks/useServer.ts',
name: 'useServer',
default: true,
},
},
}
},
});
And a hook for axios:
import { useContext } from 'react';
import { AxiosRequestConfig } from 'axios';
import { AxiosContext } from '../components/AxiosProvider';
const useServer = <T>(): ((
config: AxiosRequestConfig,
options?: AxiosRequestConfig,
) => Promise<T>) => {
const { axios } = useContext(AxiosContext);
return (config: AxiosRequestConfig, options?: AxiosRequestConfig) => {
return axios({
...config,
...options,
}).then(({ data }) => data);
};
};
export default useServer;
However, when I generate the code using orval, looks like it doesn’t add the second parameter:
Maybe I’m doing something wrong. Let me know if I’m missing something.
Thanks.
Issue Analytics
- State:
- Created a year ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Request not responding, Why an OPTIONS method is sent ...
I've been having a problem i don't really have using jQuery Ajax methods, when i use axios, my request sends one Request Method:OPTIONS...
Read more >Data Fetching with React Query & Axios | by Alex Streza
Axios is a solid library don't get me wrong but react-query brings a caching mechanism under the hood and its API is incredibly...
Read more >Axios get in url works but with second parameter as object it ...
axios.get accepts a request config as the second parameter (not query string params). You can use the params config option to set query...
Read more >react-query-swagger - npm
Generates react -query hooks for your API based on Swagger/OpenAPI ... There are no other projects in the npm registry using react-query-swagger.
Read more >React Query 3: A Guide to Fetching and Managing Data
Need to fetch data in React? Learn about React Query, an excellent server state management library for simplifying your data-fetching needs.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Great! Also thanks for the support 😊
@anymaniax Works perfectly. Thank you.