Cannot get react-query (useQuery hook) to work with Storybook with external API
See original GitHub issueI am using storybook to develop my react components in isolation. I am running into an issue with using react-query (useQuery) with storybook. Implementing the component in the app, I get no errors and things work as expected.
async function searchStationsByCallLetter(_, param) {
const request = {
callLettersView: param,
};
const { data } = await ApiService().makeApiCall(API_ENDPOINTS.BROADCAST_LINEUP.SEARCH_STATIONS, request, HTTP_POST);
return data;
}
export default function useSearchStationsByCallLetter(inputValue = '') {
return useQuery(['searchStationsByCallLetter', inputValue], searchStationsByCallLetter);
I have a custom react hook useSearchStationsByCallLetter that returns the useQuery hook. React-query should be using searchStationsByCallLetter as the api call. ApiService and makeApiCall are a custom axios setup.
The error I get in storybook is:
TypeError: Object(...) is not a function
at _callee$ (AddLineupHooks.js:8)
at tryCatch (runtime.js:63)
at Generator.invoke [as _invoke] (runtime.js:293)
at Generator.next (runtime.js:118)
at asyncGeneratorStep (asyncToGenerator.js:3)
at _next (asyncToGenerator.js:25)
at asyncToGenerator.js:32
at new Promise (<anonymous>)
at Object.<anonymous> (asyncToGenerator.js:21)
at Object.searchStationsByCallLetter [as queryFn] (AddLineupHooks.js:8)
Desktop (please complete the following information):
- OS: Mac
- Browser: chrome
- Version: latests
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Cannot get react-query (useQuery hook) to work ... - Issuehunt
I have a custom react hook useSearchStationsByCallLetter that returns the useQuery hook. React-query should be using searchStationsByCallLetter as the api call.
Read more >Use react-query (useQuery) with Storybook getting error
I have a custom react hook useSearchStationsByCallLetter that returns the useQuery hook. React-query should be using searchStationsByCallLetter ...
Read more >Testing React components - Apollo GraphQL Docs
This article describes best practices for testing React components that use Apollo Client. The examples below use Jest and React Testing Library, ...
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 5 react-query Code Examples - Snyk
To help you get started, we've selected a few react-query examples, based on popular ways it is used in public projects. Secure your...
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 Free
Top 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
@sdivelbiss i’ve kept track of your issue while i was working on getting Storybook and React Query working nicely with Axios.
Here’s what i did:
.storybook/preview.js
to the following to allow react-query cache provider,the react-query-devtools and my mock service working with Storybook:use-query
with the following code:AxiosRestExample.stories.js
with the following:AxiosRestPostExample.js
with the following:AxiosRestPostExample.stories.js
:src/mocks/server
with the following inside:src/mocks/handlers
with the following:yarn storybook
and i get the following:I know that this is a rather small and possibly skewed approach to the problem. But it seems that Storybook and React-Query will work fine together.
If you can provide additional information about how you’re implementing the associated story file and how you’ve setup Axios we could take a look at it and probably provide you with a more concrete answer.
Or i can hoist up this small reproduction to a repo and you can take a look at it in your time. Let us know and we’ll move from there.
Stay safe
Maybe my question is not exactly regards this topic, but may be someone can answer. The case when I need to show only the loading state from react-query, what should I do in this case?